Skip to contentSkip to conversation

setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros

PATCH Superseded Avinesh Kumar 1 participant 2 messages Jul 27, 2022 – Aug 11, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros

use TST_EXP_FAIL() with expected errno code, use SAFE_SETUID() in setup and turn comment into docparse

---
 testcases/kernel/syscalls/setuid/setuid03.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/setuid/setuid03.c +5 -15
index f2e007f8d..61529b1ff 100644
@@ -3,7 +3,9 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/* DESCRIPTION
+/*
+ * [Description]
+ *
  * This test will switch to nobody user for correct error code collection.
  * Verify setuid returns errno EPERM when it switches to root_user.
  */
@@ -19,16 +21,7 @@
 
 static void verify_setuid(void)
 {
-	TEST(SETUID(ROOT_USER));
-	if (TST_RET != -1) {
-		tst_res(TFAIL | TTERRNO, "setuid() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == EPERM)
-		tst_res(TPASS, "setuid() returned errno EPERM");
-	else
-		tst_res(TFAIL | TTERRNO, "setuid() returned unexpected errno");
+	TST_EXP_FAIL(SETUID(ROOT_USER), EPERM);
 }
 
 static void setup(void)
@@ -39,10 +32,7 @@ static void setup(void)
 	pw = SAFE_GETPWNAM("nobody");
 	uid = pw->pw_uid;
 
-	if (SETUID(uid) == -1) {
-		tst_brk(TBROK,
-			"setuid() failed to set the effective uid to %d", uid);
-	}
+	SAFE_SETUID(uid);
 
 	umask(0);
 }
Signature · 5 lines
2.36.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Sent a v2 for this with correct docparse format and updated copyright.

Quoted 44 lines · IST Avinesh Kumar

use TST_EXP_FAIL() with expected errno code, use SAFE_SETUID() in setup and turn comment into docparse

---
 testcases/kernel/syscalls/setuid/setuid03.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/setuid/setuid03.c +4 -11
index f2e007f8d..61529b1ff 100644
@@ -3,7 +3,9 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/* DESCRIPTION
+/*
+ * [Description]
+ *
  * This test will switch to nobody user for correct error code collection.
  * Verify setuid returns errno EPERM when it switches to root_user.
  */
@@ -19,16 +21,7 @@
 
 static void verify_setuid(void)
 {
-	TEST(SETUID(ROOT_USER));
-	if (TST_RET != -1) {
-		tst_res(TFAIL | TTERRNO, "setuid() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == EPERM)
-		tst_res(TPASS, "setuid() returned errno EPERM");
-	else
-		tst_res(TFAIL | TTERRNO, "setuid() returned unexpected errno");
+	TST_EXP_FAIL(SETUID(ROOT_USER), EPERM);
 }
 
 static void setup(void)
@@ -39,10 +32,7 @@ static void setup(void)
 	pw = SAFE_GETPWNAM("nobody");

testcases/kernel/syscalls/setuid/setuid03.c static void setup(void) · line 38

Quoted 10 lines
testcases/kernel/syscalls/setuid/setuid03.c +1 -4
 	uid = pw->pw_uid;
 
-	if (SETUID(uid) == -1) {
-		tst_brk(TBROK,
-			"setuid() failed to set the effective uid to %d", uid);
-	}
+	SAFE_SETUID(uid);
 
 	umask(0);
 }

Regards,
Avinesh

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp