Fix sigsegv in check_stream in smbtorture smb2.streams.io
authorGordon Ross <gordon.ross@tintri.com>
Mon, 19 Apr 2021 22:31:13 +0000 (18:31 -0400)
committerJeremy Allison <jra@samba.org>
Thu, 22 Apr 2021 18:48:30 +0000 (18:48 +0000)
torture_comment calls need a struct torture_context arg,
not its mem_ctx child.  Use talloc_parent().  Also
need to call torture_result somewhere on failure.

Signed-off-by: Gordon Ross <gordon.ross@tintri.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Mulder <dmulder@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Apr 22 18:48:30 UTC 2021 on sn-devel-184

source4/torture/smb2/streams.c

index c0516b7cc803a0e48270564b3334c1fceed1efc3..814ed1666c70b71cab4b83e047a9fd3cb1a7462c 100644 (file)
@@ -91,7 +91,8 @@ static int qsort_stream(const struct stream_struct * s1, const struct stream_str
        return strcmp(s1->stream_name.s, s2->stream_name.s);
 }
 
-static bool check_stream(struct smb2_tree *tree,
+static bool check_stream(struct torture_context *tctx,
+                        struct smb2_tree *tree,
                         const char *location,
                         TALLOC_CTX *mem_ctx,
                         const char *fname,
@@ -117,7 +118,7 @@ static bool check_stream(struct smb2_tree *tree,
                if (value == NULL) {
                        return true;
                } else {
-                       torture_comment(mem_ctx, "Unable to open stream %s\n",
+                       torture_comment(tctx, "Unable to open stream %s\n",
                            full_name);
                        return false;
                }
@@ -137,13 +138,13 @@ static bool check_stream(struct smb2_tree *tree,
        status = smb2_read(tree, tree, &r);
 
        if (!NT_STATUS_IS_OK(status)) {
-               torture_comment(mem_ctx, "(%s) Failed to read %lu bytes from "
+               torture_comment(tctx, "(%s) Failed to read %lu bytes from "
                    "stream '%s'\n", location, (long)strlen(value), full_name);
                return false;
        }
 
        if (memcmp(r.out.data.data, value, strlen(value)) != 0) {
-               torture_comment(mem_ctx, "(%s) Bad data in stream\n", location);
+               torture_comment(tctx, "(%s) Bad data in stream\n", location);
                return false;
        }
 
@@ -349,7 +350,7 @@ static bool test_stream_io(struct torture_context *tctx,
        CHECK_STATUS(status, NT_STATUS_OK);
        h2 = io.smb2.out.file.handle;
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Stream One", NULL);
 
        torture_comment(tctx, "(%s) check that open of base file is allowed\n", __location__);
@@ -365,7 +366,7 @@ static bool test_stream_io(struct torture_context *tctx,
 
        smb2_util_close(tree, h2);
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Stream One", "test data");
 
        io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
@@ -380,7 +381,7 @@ static bool test_stream_io(struct torture_context *tctx,
 
        smb2_util_close(tree, h2);
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Stream One:$FOO", NULL);
 
        torture_comment(tctx, "(%s) creating a stream2 on a existing file\n",
@@ -396,29 +397,41 @@ static bool test_stream_io(struct torture_context *tctx,
        CHECK_STATUS(status, NT_STATUS_OK);
        smb2_util_close(tree, h2);
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                             "Stream One", "test MORE DATA ");
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Stream One:$DATA", "test MORE DATA ");
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Stream One:", NULL);
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       if (!ret) {
+               torture_result(tctx, TORTURE_FAIL,
+                   "check_stream(\"Stream One:*\") failed\n");
+               goto done;
+       }
+
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Second Stream", "SECOND STREAM");
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "SECOND STREAM:$DATA", "SECOND STREAM");
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Second Stream:$DATA", "SECOND STREAM");
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Second Stream:", NULL);
 
-       ret &= check_stream(tree, __location__, mem_ctx, fname,
+       ret &= check_stream(tctx, tree, __location__, mem_ctx, fname,
                            "Second Stream:$FOO", NULL);
 
+       if (!ret) {
+               torture_result(tctx, TORTURE_FAIL,
+                   "check_stream(\"Second Stream:*\") failed\n");
+               goto done;
+       }
+
        io.smb2.in.fname = sname2;
        io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
        status = smb2_create(tree, mem_ctx, &(io.smb2));