]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb: Return early if dir is NULL
authorAndreas Schneider <asn@samba.org>
Wed, 25 Nov 2020 12:01:46 +0000 (13:01 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 26 Nov 2020 11:07:09 +0000 (11:07 +0000)
This makes sure we do not dereference a NULL poineter.

Found by covscan.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Nov 26 11:07:09 UTC 2020 on sn-devel-184

source3/libsmb/libsmb_dir.c

index 27d0fbd4db56a324e37a38d3d745f6a64ae8f3bd..f1596b743efc55b41b87ea7f16822fef918c5d9f 100644 (file)
@@ -1041,14 +1041,19 @@ int
 SMBC_closedir_ctx(SMBCCTX *context,
                   SMBCFILE *dir)
 {
-       TALLOC_CTX *frame = talloc_stackframe();
+       TALLOC_CTX *frame = NULL;
 
        if (!context || !context->internal->initialized) {
                errno = EINVAL;
-               TALLOC_FREE(frame);
                return -1;
        }
 
+       if (dir == NULL) {
+               return 0;
+       }
+
+       frame = talloc_stackframe();
+
        if (!SMBC_dlist_contains(context->internal->files, dir)) {
                errno = EBADF;
                TALLOC_FREE(frame);
@@ -1060,11 +1065,8 @@ SMBC_closedir_ctx(SMBCCTX *context,
 
        DLIST_REMOVE(context->internal->files, dir);
 
-       if (dir) {
-
-               SAFE_FREE(dir->fname);
-               SAFE_FREE(dir);    /* Free the space too */
-       }
+       SAFE_FREE(dir->fname);
+       SAFE_FREE(dir);    /* Free the space too */
 
        TALLOC_FREE(frame);
        return 0;