krb5 commit [krb5-1.12]: Check for asprintf failure in kdb5_util create

Tom Yu tlyu at MIT.EDU
Thu Jun 26 17:41:02 EDT 2014


https://github.com/krb5/krb5/commit/84a258e3976906332b9b9eec651e669e8ddd1989
commit 84a258e3976906332b9b9eec651e669e8ddd1989
Author: Tomas Kuthan <tkuthan at gmail.com>
Date:   Thu Apr 10 15:16:06 2014 +0200

    Check for asprintf failure in kdb5_util create
    
    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 at mit.edu: rewrite commit message]
    
    (cherry picked from commit f5645d30cf83398640c386a612eb6f07c543286f)
    
    ticket: 7902
    version_fixed: 1.12.2
    status: resolved

 src/kadmin/dbutil/kadm5_create.c |   30 ++++--------------------------
 1 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/src/kadmin/dbutil/kadm5_create.c b/src/kadmin/dbutil/kadm5_create.c
index 40f89a7..5d2854a 100644
--- a/src/kadmin/dbutil/kadm5_create.c
+++ b/src/kadmin/dbutil/kadm5_create.c
@@ -126,31 +126,6 @@ int kadm5_create_magic_princs(kadm5_config_params *params,
 }
 
 /*
- * 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 at 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
  *
  * Purpose: create admin principals
@@ -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"));


More information about the cvs-krb5 mailing list