From: Tom Yu Date: Mon, 13 Jul 2015 22:05:35 +0000 (-0400) Subject: Fix princflags memory management X-Git-Tag: krb5-1.14-alpha1~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F295%2Fhead;p=thirdparty%2Fkrb5.git Fix princflags memory management Fix some out of memory error cases (found by Coverity) that could cause multiple frees or freeing of invalid pointers. In krb5_flagnum_to_string(), don't assume that asprintf() stores a null pointer on failure (it does in BSD but not in glibc). In krb5_flags_to_strings(), free the correct pointer in the cleanup loop in on error. ticket: 8215 --- diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c index fd9a1d178a..0441a17682 100644 --- a/src/lib/kadm5/str_conv.c +++ b/src/lib/kadm5/str_conv.c @@ -196,7 +196,8 @@ krb5_flagspec_to_mask(const char *spec, krb5_flags *toset, krb5_flags *toclear) } /* - * Copy the flag name of flagnum to outstr. + * Copy the flag name of flagnum to outstr. On error, outstr points to a null + * pointer. */ krb5_error_code krb5_flagnum_to_string(int flagnum, char **outstr) @@ -204,14 +205,15 @@ krb5_flagnum_to_string(int flagnum, char **outstr) const char *s = NULL; *outstr = NULL; - if ((unsigned int)flagnum < NOUTFLAGS) { + if ((unsigned int)flagnum < NOUTFLAGS) s = outflags[flagnum]; - } - if (s == NULL) + if (s == NULL) { /* Assume that krb5_flags are 32 bits long. */ - asprintf(outstr, "0x%08lx", 1UL<