]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix minor cleanup issue in file ccache
authorGreg Hudson <ghudson@mit.edu>
Tue, 4 Nov 2014 15:13:11 +0000 (10:13 -0500)
committerGreg Hudson <ghudson@mit.edu>
Wed, 5 Nov 2014 19:53:59 +0000 (14:53 -0500)
If we fail to open the cache file in fcc_initialize, we could wind up
calling close(-1) which is harmless but incorrect.  Avoid this by
initializing fd and conditionalizing its cleanup.

ticket: 8026

src/lib/krb5/ccache/cc_file.c

index cd6fb9dbc7cd2e35635e77831ddc1b62530da898..e220971a7f8426350e6b092f4f64f4e84c0459c7 100644 (file)
@@ -446,7 +446,7 @@ fcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ)
     char i16buf[2], i32buf[4];
     uint16_t fields_len;
     ssize_t nwritten;
-    int st, fd, flags, version;
+    int st, flags, version, fd = -1;
     struct k5buf buf = EMPTY_K5BUF;
     krb5_boolean file_locked = FALSE;
 
@@ -518,7 +518,8 @@ cleanup:
     k5_buf_free(&buf);
     if (file_locked)
         krb5_unlock_file(context, fd);
-    close(fd);
+    if (fd != -1)
+        close(fd);
     k5_cc_mutex_unlock(context, &data->lock);
     krb5_change_cache();
     return ret;