krb5 commit: Allow null inputs to response item functions

Greg Hudson ghudson at MIT.EDU
Fri Oct 12 11:44:48 EDT 2012


https://github.com/krb5/krb5/commit/816c7b59c3869e004d4ad150c7f04d026bb42177
commit 816c7b59c3869e004d4ad150c7f04d026bb42177
Author: Nathaniel McCallum <npmccallum at redhat.com>
Date:   Fri Oct 12 10:30:09 2012 -0400

    Allow null inputs to response item functions

 src/lib/krb5/krb/response_items.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/lib/krb5/krb/response_items.c b/src/lib/krb5/krb/response_items.c
index 243df48..606d4f3 100644
--- a/src/lib/krb5/krb/response_items.c
+++ b/src/lib/krb5/krb/response_items.c
@@ -53,6 +53,9 @@ k5_response_items_reset(k5_response_items *ri)
 {
     size_t i;
 
+    if (ri == NULL)
+        return;
+
     for (i = 0; i < ri->count; i++)
         free(ri->questions[i]);
     free(ri->questions);
@@ -74,12 +77,14 @@ k5_response_items_reset(k5_response_items *ri)
 krb5_boolean
 k5_response_items_empty(const k5_response_items *ri)
 {
-    return ri->count == 0;
+    return ri == NULL ? TRUE : ri->count == 0;
 }
 
 const char * const *
 k5_response_items_list_questions(const k5_response_items *ri)
 {
+    if (ri == NULL)
+        return NULL;
     return (const char * const *)ri->questions;
 }
 
@@ -88,6 +93,9 @@ find_question(const k5_response_items *ri, const char *question)
 {
     size_t i;
 
+    if (ri == NULL)
+        return -1;
+
     for (i = 0; i < ri->count; i++) {
         if (strcmp(ri->questions[i], question) == 0)
             return i;
@@ -101,8 +109,12 @@ push_question(k5_response_items *ri, const char *question,
               const char *challenge)
 {
     char **tmp;
-    const size_t size = sizeof(char*) * (ri->count + 2);
+    size_t size;
+
+    if (ri == NULL)
+        return EINVAL;
 
+    size = sizeof(char *) * (ri->count + 2);
     tmp = realloc(ri->questions, size);
     if (tmp == NULL)
         return ENOMEM;


More information about the cvs-krb5 mailing list