lib/krb5_wrap: make sure smb_krb5_principal_get_realm returns a malloced string.
authorGünther Deschner <gd@samba.org>
Thu, 15 May 2014 07:44:23 +0000 (09:44 +0200)
committerGünther Deschner <gd@samba.org>
Fri, 8 Aug 2014 14:37:36 +0000 (16:37 +0200)
Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/krb5_wrap/krb5_samba.c

index a3743aef44976b500c493f2c89427b7ff2ba5608..8e560d2df3f8eb5eba8d21a17c1f827c8bb0a949 100644 (file)
@@ -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
 }