s3-keytab: fix keytab array NULL termination.
authorMatt Rogers <mrogers@redhat.com>
Wed, 12 Nov 2014 16:21:05 +0000 (17:21 +0100)
committerKarolin Seeger <kseeger@samba.org>
Mon, 17 Nov 2014 20:21:12 +0000 (21:21 +0100)
Signed-off-by: Matt Rogers <mrogers@redhat.com>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 0de6799996955fbf8e19ace8c4b7b61f5a262cb5)

BUG: https://bugzilla.samba.org/show_bug.cgi?id=10933
net ads join -k can segfault with existing keytab entries

source3/libads/kerberos_keytab.c

index d13625b27e78e4e4381f692d3772ae179c10b067..56f0a772b51bb189ee1d76f41ad5b99070e63c6b 100644 (file)
@@ -664,14 +664,13 @@ int ads_keytab_create_default(ADS_STRUCT *ads)
                goto done;
        }
 
-       oldEntries = talloc_array(frame, char *, found);
+       oldEntries = talloc_zero_array(frame, char *, found + 1);
        if (!oldEntries) {
                DEBUG(1, (__location__ ": Failed to allocate space to store "
                          "the old keytab entries (talloc failed?).\n"));
                ret = -1;
                goto done;
        }
-       memset(oldEntries, '\0', found * sizeof(char *));
 
        ret = krb5_kt_start_seq_get(context, keytab, &cursor);
        if (ret == KRB5_KT_END || ret == ENOENT) {