From 998417af98c4690765d533136cf484fd1ce96777 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sat, 24 Sep 2011 12:19:21 +0000 Subject: [PATCH] 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. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25230 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/kdb5.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lib/kdb/kdb5.c b/src/lib/kdb/kdb5.c index 4dfe66151..a3a0d6f49 100644 --- a/src/lib/kdb/kdb5.c +++ b/src/lib/kdb/kdb5.c @@ -2048,16 +2048,14 @@ krb5_dbe_get_strings(krb5_context context, krb5_db_entry *entry, while (next_attr(&pos, end, &mapkey, &mapval)) { /* Add a copy of mapkey and mapvalue to strings. */ - 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; - } + if (newstrings == NULL) + goto oom; strings = newstrings; + key = strdup(mapkey); + val = strdup(mapval); + if (key == NULL || val == NULL) + goto oom; strings[count].key = key; strings[count].value = val; count++; @@ -2066,6 +2064,12 @@ krb5_dbe_get_strings(krb5_context context, krb5_db_entry *entry, *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 -- 2.26.2