Check for asprintf failure in kdb5_util create master
authorTomas Kuthan <tkuthan@gmail.com>
Thu, 10 Apr 2014 13:16:06 +0000 (15:16 +0200)
committerGreg Hudson <ghudson@mit.edu>
Tue, 15 Apr 2014 17:35:49 +0000 (13:35 -0400)
In add_admin_princ, remove build_name_with_realm and call asprintf
directly instead.  Check for asprintf failure to avoid passing an
undefined pointer to krb5_parse_name.

[ghudson@mit.edu: rewrite commit message]

ticket: 7902 (new)
target_version: 1.12.2
tags: pullup

src/kadmin/dbutil/kadm5_create.c

index 40f89a7ce27e1acd8baa3171628455a5da8cd6c3..5d2854ad2eab601af13656bb404cf70b36cbbb6c 100644 (file)
@@ -125,31 +125,6 @@ int kadm5_create_magic_princs(kadm5_config_params *params,
     return retval;
 }
 
-/*
- * Function: build_name_with_realm
- *
- * Purpose: concatenate a name and a realm to form a krb5 name
- *
- * Arguments:
- *
- *      name    (input) the name
- *      realm   (input) the realm
- *
- * Returns:
- *
- *      pointer to name@realm, in allocated memory, or NULL if it
- *      cannot be allocated
- *
- * Requires: both strings are null-terminated
- */
-static char *build_name_with_realm(char *name, char *realm)
-{
-    char *n;
-
-    asprintf(&n, "%s@%s", name, realm);
-    return n;
-}
-
 /*
  * Function: add_admin_princs
  *
@@ -284,7 +259,10 @@ int add_admin_princ(void *handle, krb5_context context,
 
     memset(&ent, 0, sizeof(ent));
 
-    fullname = build_name_with_realm(name, realm);
+    if (asprintf(&fullname, "%s@%s", name, realm) < 0) {
+        com_err(progname, ENOMEM, _("while appending realm to principal"));
+        return ERR;
+    }
     ret = krb5_parse_name(context, fullname, &ent.principal);
     if (ret) {
         com_err(progname, ret, _("while parsing admin principal name"));