Skip to content

Commit

Permalink
Check for asprintf failure in kdb5_util create
Browse files Browse the repository at this point in the history
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]

(cherry picked from commit f5645d3)

ticket: 7902
version_fixed: 1.12.2
status: resolved
  • Loading branch information
tkuthan authored and tlyu committed Jun 26, 2014
1 parent 6d40fad commit 84a258e
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions src/kadmin/dbutil/kadm5_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 84a258e

Please sign in to comment.