svn rev #25230: trunk/src/lib/kdb/

ghudson@MIT.EDU ghudson at MIT.EDU
Sat Sep 24 08:19:21 EDT 2011


http://src.mit.edu/fisheye/changelog/krb5/?cs=25230
Commit By: ghudson
Log Message:
Fix krb5_dbe_get_strings error handling.

The old error handling was incorrect in the case where a strdup() call
returns NULL but realloc() returns non-NULL.


Changed Files:
U   trunk/src/lib/kdb/kdb5.c
Modified: trunk/src/lib/kdb/kdb5.c
===================================================================
--- trunk/src/lib/kdb/kdb5.c	2011-09-24 12:19:14 UTC (rev 25229)
+++ trunk/src/lib/kdb/kdb5.c	2011-09-24 12:19:21 UTC (rev 25230)
@@ -2048,16 +2048,14 @@
 
     while (next_attr(&pos, end, &mapkey, &mapval)) {
         /* Add a copy of mapkey and mapvalue to strings. */
+        newstrings = realloc(strings, (count + 1) * sizeof(*strings));
+        if (newstrings == NULL)
+            goto oom;
+        strings = newstrings;
         key = strdup(mapkey);
         val = strdup(mapval);
-        newstrings = realloc(strings, (count + 1) * sizeof(*strings));
-        if (key == NULL || val == NULL || newstrings == NULL) {
-            free(key);
-            free(val);
-            krb5_dbe_free_strings(context, strings, count);
-            return ENOMEM;
-        }
-        strings = newstrings;
+        if (key == NULL || val == NULL)
+            goto oom;
         strings[count].key = key;
         strings[count].value = val;
         count++;
@@ -2066,6 +2064,12 @@
     *strings_out = strings;
     *count_out = count;
     return 0;
+
+oom:
+    free(key);
+    free(val);
+    krb5_dbe_free_strings(context, strings, count);
+    return ENOMEM;
 }
 
 krb5_error_code




More information about the cvs-krb5 mailing list