s3: krb5: keytab - The done label can be jumped to with context == NULL.
authorJeremy Allison <jra@samba.org>
Wed, 8 Jun 2016 21:50:59 +0000 (14:50 -0700)
committerUri Simchoni <uri@samba.org>
Thu, 9 Jun 2016 11:18:56 +0000 (13:18 +0200)
Ensure we don't crash in this case.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11959

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
Autobuild-User(master): Uri Simchoni <uri@samba.org>
Autobuild-Date(master): Thu Jun  9 13:18:56 CEST 2016 on sn-devel-144

source3/libads/kerberos_keytab.c

index 731895e0bc2a0d9aefb74b00fb0aeb739aec3ffb..160b58396a4caf7aa4286550a0c396ffb480c492 100644 (file)
@@ -552,26 +552,24 @@ done:
        TALLOC_FREE(oldEntries);
        TALLOC_FREE(frame);
 
-       {
+       if (context) {
                krb5_keytab_entry zero_kt_entry;
+               krb5_kt_cursor zero_csr;
+
                ZERO_STRUCT(zero_kt_entry);
+               ZERO_STRUCT(zero_csr);
+
                if (memcmp(&zero_kt_entry, &kt_entry,
                                sizeof(krb5_keytab_entry))) {
                        smb_krb5_kt_free_entry(context, &kt_entry);
                }
-       }
-       {
-               krb5_kt_cursor zero_csr;
-               ZERO_STRUCT(zero_csr);
                if ((memcmp(&cursor, &zero_csr,
                                sizeof(krb5_kt_cursor)) != 0) && keytab) {
                        krb5_kt_end_seq_get(context, keytab, &cursor);
                }
-       }
-       if (keytab) {
-               krb5_kt_close(context, keytab);
-       }
-       if (context) {
+               if (keytab) {
+                       krb5_kt_close(context, keytab);
+               }
                krb5_free_context(context);
        }
        return ret;