Module Name:    src
Committed By:   riastradh
Date:           Fri Nov 24 17:31:03 UTC 2023

Modified Files:
        src/tests/fs/hfs: t_pathconvert.c
        src/tests/kernel: t_memfd_create.c
        src/tests/lib/librefuse: t_refuse_opt.c
        src/tests/lib/librumpclient: t_fd.c

Log Message:
tests: Audit RZ abuse.

RZ succeeds if x is zero, and fails if x is nonzero, treating a
nonzero value as a error number as in errno(3) to print the message.

The following library routines instead return -1 on failure and set
errno to the error code:

fuse_opt_add_arg
fuse_opt_add_opt
fuse_opt_add_opt_escaped
fuse_opt_insert_arg
lseek
system

So use RL instead for those -- succeeds if x is zero, and fails if x
is -1.

This shouldn't make any tests newly fail or newly succeed -- the
functions in question only ever return 0 or -1 -- but if the tests
were already failing anywhere, they will now fail with meaningful
messages.

TBD: dlinfo, which isn't fit for RL or RZ since it reports errors via
dlerror() rather than errno.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/fs/hfs/t_pathconvert.c
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_memfd_create.c
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/librefuse/t_refuse_opt.c
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/librumpclient/t_fd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/fs/hfs/t_pathconvert.c
diff -u src/tests/fs/hfs/t_pathconvert.c:1.7 src/tests/fs/hfs/t_pathconvert.c:1.8
--- src/tests/fs/hfs/t_pathconvert.c:1.7	Tue Jul  9 16:24:01 2019
+++ src/tests/fs/hfs/t_pathconvert.c	Fri Nov 24 17:31:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_pathconvert.c,v 1.7 2019/07/09 16:24:01 maya Exp $	*/
+/*	$NetBSD: t_pathconvert.c,v 1.8 2023/11/24 17:31:03 riastradh Exp $	*/
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -42,10 +42,10 @@ ATF_TC_BODY(colonslash, tc)
 
 	snprintf(thecmd, sizeof(thecmd), "uudecode %s/colon.hfs.bz2.uue",
 	    atf_tc_get_config_var(tc, "srcdir"));
-	RZ(system(thecmd));
+	RL(system(thecmd));
 
 	snprintf(thecmd, sizeof(thecmd), "bunzip2 " IMGNAME ".bz2");
-	RZ(system(thecmd));
+	RL(system(thecmd));
 
 	memset(&args, 0, sizeof args);
 	args.fspec = __UNCONST(FAKEBLK);

Index: src/tests/kernel/t_memfd_create.c
diff -u src/tests/kernel/t_memfd_create.c:1.2 src/tests/kernel/t_memfd_create.c:1.3
--- src/tests/kernel/t_memfd_create.c:1.2	Sat Jul 29 16:24:35 2023
+++ src/tests/kernel/t_memfd_create.c	Fri Nov 24 17:31:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_memfd_create.c,v 1.2 2023/07/29 16:24:35 rin Exp $	*/
+/*	$NetBSD: t_memfd_create.c,v 1.3 2023/11/24 17:31:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_memfd_create.c,v 1.2 2023/07/29 16:24:35 rin Exp $");
+__RCSID("$NetBSD: t_memfd_create.c,v 1.3 2023/11/24 17:31:03 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -109,7 +109,7 @@ ATF_TC_BODY(read_write, tc)
 	    "File offset not set after write (%jd != %zu)", (intmax_t)offset,
 	    sizeof(write_buf));
 
-	RZ(lseek(fd, 0, SEEK_SET));
+	RL(lseek(fd, 0, SEEK_SET));
 
 	RL(read(fd, read_buf, sizeof(read_buf)));
 	offset = lseek(fd, 0, SEEK_CUR);
@@ -158,7 +158,7 @@ ATF_TC_BODY(truncate, tc)
 	    "Truncate did not grow size to %zu (is %jd)", sizeof(read_buf),
 	    (intmax_t)st.st_size);
 
-	RZ(lseek(fd, 0, SEEK_SET));
+	RL(lseek(fd, 0, SEEK_SET));
 	RL(read(fd, read_buf, sizeof(read_buf)));
 
 	for (size_t i = 0; i < sizeof(read_buf)/2; i++)
@@ -255,7 +255,7 @@ test_all_seals_except(int fd, int except
 	}
 
 	if (except & ~(F_SEAL_WRITE|F_SEAL_FUTURE_WRITE)) {
-		RZ(lseek(fd, 0, SEEK_SET));
+		RL(lseek(fd, 0, SEEK_SET));
 		rv = write(fd, write_buf, sizeof(write_buf));
 		if (rv == -1) {
 			ATF_REQUIRE_MSG(errno != EPERM,

Index: src/tests/lib/librefuse/t_refuse_opt.c
diff -u src/tests/lib/librefuse/t_refuse_opt.c:1.9 src/tests/lib/librefuse/t_refuse_opt.c:1.10
--- src/tests/lib/librefuse/t_refuse_opt.c:1.9	Sat Dec  4 06:42:39 2021
+++ src/tests/lib/librefuse/t_refuse_opt.c	Fri Nov 24 17:31:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_refuse_opt.c,v 1.9 2021/12/04 06:42:39 pho Exp $ */
+/*	$NetBSD: t_refuse_opt.c,v 1.10 2023/11/24 17:31:03 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_refuse_opt.c,v 1.9 2021/12/04 06:42:39 pho Exp $");
+__RCSID("$NetBSD: t_refuse_opt.c,v 1.10 2023/11/24 17:31:03 riastradh Exp $");
 
 #include <sys/types.h>
 
@@ -47,8 +47,8 @@ ATF_TC_BODY(t_fuse_opt_add_arg, tc)
 {
 	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
 
-	RZ(fuse_opt_add_arg(&args, "foo"));
-	RZ(fuse_opt_add_arg(&args, "bar"));
+	RL(fuse_opt_add_arg(&args, "foo"));
+	RL(fuse_opt_add_arg(&args, "bar"));
 
 	ATF_REQUIRE_EQ(args.argc, 2);
 	ATF_CHECK_STREQ(args.argv[0], "foo");
@@ -66,8 +66,8 @@ ATF_TC_BODY(t_fuse_opt_insert_arg, tc)
 {
 	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
 
-	RZ(fuse_opt_insert_arg(&args, 0, "foo"));
-	RZ(fuse_opt_insert_arg(&args, 0, "bar"));
+	RL(fuse_opt_insert_arg(&args, 0, "foo"));
+	RL(fuse_opt_insert_arg(&args, 0, "bar"));
 
 	ATF_REQUIRE_EQ(args.argc, 2);
 	ATF_CHECK_STREQ(args.argv[0], "bar");
@@ -85,10 +85,10 @@ ATF_TC_BODY(t_fuse_opt_add_opt, tc)
 {
 	char* opt = NULL;
 
-	RZ(fuse_opt_add_opt(&opt, "fo\\o"));
+	RL(fuse_opt_add_opt(&opt, "fo\\o"));
 	ATF_CHECK_STREQ(opt, "fo\\o");
 
-	RZ(fuse_opt_add_opt(&opt, "ba,r"));
+	RL(fuse_opt_add_opt(&opt, "ba,r"));
 	ATF_CHECK_STREQ(opt, "fo\\o,ba,r");
 }
 
@@ -102,10 +102,10 @@ ATF_TC_BODY(t_fuse_opt_add_opt_escaped, 
 {
 	char* opt = NULL;
 
-	RZ(fuse_opt_add_opt_escaped(&opt, "fo\\o"));
+	RL(fuse_opt_add_opt_escaped(&opt, "fo\\o"));
 	ATF_CHECK_STREQ(opt, "fo\\\\o");
 
-	RZ(fuse_opt_add_opt_escaped(&opt, "ba,r"));
+	RL(fuse_opt_add_opt_escaped(&opt, "ba,r"));
 	ATF_CHECK_STREQ(opt, "fo\\\\o,ba\\,r");
 }
 
@@ -207,10 +207,10 @@ ATF_TC_BODY(t_fuse_opt_parse_null_opts, 
 	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
 	struct foofs_config config;
 
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "number=1,string=foo"));
-	RZ(fuse_opt_add_arg(&args, "bar"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "number=1,string=foo"));
+	RL(fuse_opt_add_arg(&args, "bar"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, NULL, NULL) == 0);
@@ -236,10 +236,10 @@ ATF_TC_BODY(t_fuse_opt_parse_null_proc, 
 	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
 	struct foofs_config config;
 
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "number=1,string=foo"));
-	RZ(fuse_opt_add_arg(&args, "bar"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "number=1,string=foo"));
+	RL(fuse_opt_add_arg(&args, "bar"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, NULL) == 0);
@@ -264,10 +264,10 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
     /* Standard form */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "number=1,string=foo"));
-	RZ(fuse_opt_add_arg(&args, "bar"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "number=1,string=foo"));
+	RL(fuse_opt_add_arg(&args, "bar"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -279,9 +279,9 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
     /* Concatenated -o */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-onumber=1,unknown,string=foo"));
-	RZ(fuse_opt_add_arg(&args, "bar"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-onumber=1,unknown,string=foo"));
+	RL(fuse_opt_add_arg(&args, "bar"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -295,15 +295,15 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* Sparse -o */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "bar"));
-	RZ(fuse_opt_add_arg(&args, "baz"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "number=1"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "unknown"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "string=foo"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "bar"));
+	RL(fuse_opt_add_arg(&args, "baz"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "number=1"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "unknown"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "string=foo"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -318,9 +318,9 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* Separate -n %i */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-n"));
-	RZ(fuse_opt_add_arg(&args, "3"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-n"));
+	RL(fuse_opt_add_arg(&args, "3"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -332,8 +332,8 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* Concatenated -n %i */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-n3"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-n3"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -345,9 +345,9 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* -o constant */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "-o"));
-	RZ(fuse_opt_add_arg(&args, "number2"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "-o"));
+	RL(fuse_opt_add_arg(&args, "number2"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -359,8 +359,8 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* -x constant */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-	RZ(fuse_opt_add_arg(&args, "--number=four"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+	RL(fuse_opt_add_arg(&args, "--number=four"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -372,10 +372,10 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* end-of-options "--" marker */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-    RZ(fuse_opt_add_arg(&args, "--"));
-	RZ(fuse_opt_add_arg(&args, "-onumber=1"));
-	RZ(fuse_opt_add_arg(&args, "-ostring=foo"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+    RL(fuse_opt_add_arg(&args, "--"));
+	RL(fuse_opt_add_arg(&args, "-onumber=1"));
+	RL(fuse_opt_add_arg(&args, "-ostring=foo"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);
@@ -389,9 +389,9 @@ ATF_TC_BODY(t_fuse_opt_parse, tc)
 
 	/* The "--" marker at the last of outargs should be removed */
 	fuse_opt_free_args(&args);
-	RZ(fuse_opt_add_arg(&args, "foofs"));
-    RZ(fuse_opt_add_arg(&args, "--"));
-	RZ(fuse_opt_add_arg(&args, "-onumber=1"));
+	RL(fuse_opt_add_arg(&args, "foofs"));
+    RL(fuse_opt_add_arg(&args, "--"));
+	RL(fuse_opt_add_arg(&args, "-onumber=1"));
 
 	memset(&config, 0, sizeof(config));
 	ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0);

Index: src/tests/lib/librumpclient/t_fd.c
diff -u src/tests/lib/librumpclient/t_fd.c:1.8 src/tests/lib/librumpclient/t_fd.c:1.9
--- src/tests/lib/librumpclient/t_fd.c:1.8	Thu Aug  3 20:45:50 2023
+++ src/tests/lib/librumpclient/t_fd.c	Fri Nov 24 17:31:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fd.c,v 1.8 2023/08/03 20:45:50 andvar Exp $	*/
+/*	$NetBSD: t_fd.c,v 1.9 2023/11/24 17:31:03 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@ ATF_TC_BODY(bigenough, tc)
 {
 	struct stat sb;
 
-	RZ(system("rump_server " RUMPSERV));
+	RL(system("rump_server " RUMPSERV));
 	RL(setenv("RUMP_SERVER", RUMPSERV, 1));
 
 	RL(dup2(0, 10));
@@ -109,7 +109,7 @@ ATF_TC_BODY(sigio, tc)
 	int sc;
 
 	signal(SIGIO, gotsig);
-	RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
+	RL(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
 	    RUMPSERV));
 	RL(setenv("RUMP_SERVER", RUMPSERV, 1));
 

Reply via email to