From: Günther Deschner Date: Thu, 15 May 2014 07:44:23 +0000 (+0200) Subject: lib/krb5_wrap: make sure smb_krb5_principal_get_realm returns a malloced string. X-Git-Tag: tdb-1.3.1~355 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=496bbd12b3dd388221334bc02a4cff21ef23b752;p=samba.git lib/krb5_wrap: make sure smb_krb5_principal_get_realm returns a malloced string. Guenther Signed-off-by: Guenther Deschner Reviewed-by: Andrew Bartlett --- diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index a3743aef449..8e560d2df3f 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -2297,19 +2297,21 @@ krb5_error_code smb_krb5_make_pac_checksum(TALLOC_CTX *mem_ctx, * @param[in] principal The principal * @return pointer to the realm * + * Caller must free if the return value is not NULL. + * */ char *smb_krb5_principal_get_realm(krb5_context context, krb5_const_principal principal) { #ifdef HAVE_KRB5_PRINCIPAL_GET_REALM /* Heimdal */ - return discard_const_p(char, krb5_principal_get_realm(context, principal)); + return strdup(discard_const_p(char, krb5_principal_get_realm(context, principal))); #elif defined(krb5_princ_realm) /* MIT */ krb5_data *realm; realm = krb5_princ_realm(context, principal); - return discard_const_p(char, realm->data); + return strndup(realm->data, realm->length); #else - return NULL; +#error UNKNOWN_GET_PRINC_REALM_FUNCTIONS #endif }