Since there is no guarantee that (USHRT_MAX - 2) uid/gid is free
on the platform it would be better to use special functions:

 * tst_get_unused_uid
 * tst_get_unused_gid

wrapped for 16-bit compatibility: if on the host there is no free uid/gid
in between [0; 0xFFFE] the 16-bit test case should return TBROK.

Signed-off-by: Stanislav Kholmanskikh <[email protected]>
---
 testcases/kernel/syscalls/setregid/setregid02.c   |    6 +++++-
 testcases/kernel/syscalls/setresuid/setresuid03.c |    8 +++++++-
 testcases/kernel/syscalls/utils/compat_gid.h      |   20 ++++++++++++++++++++
 testcases/kernel/syscalls/utils/compat_uid.h      |   20 ++++++++++++++++++++
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/setregid/setregid02.c 
b/testcases/kernel/syscalls/setregid/setregid02.c
index ccbaa3e..a730a5e 100644
--- a/testcases/kernel/syscalls/setregid/setregid02.c
+++ b/testcases/kernel/syscalls/setregid/setregid02.c
@@ -39,7 +39,7 @@ TCID_DEFINE(setregid02);
 
 static gid_t neg_one = -1;
 
-static gid_t inval_user = USHRT_MAX - 2;
+static gid_t inval_user;
 static struct passwd *ltpuser;
 
 static struct group nobody, root, bin;
@@ -177,6 +177,10 @@ static void setup(void)
        GET_GID(nobody);
        GET_GID(bin);
 
+       inval_user = GET_UNUSED_GID();
+       if (inval_user == -1)
+               tst_brkm(TBROK, NULL, "No free gid found");
+
        TEST_PAUSE;
 }
 
diff --git a/testcases/kernel/syscalls/setresuid/setresuid03.c 
b/testcases/kernel/syscalls/setresuid/setresuid03.c
index 9bb0abd..085ed7b 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid03.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid03.c
@@ -70,10 +70,12 @@
 #include <errno.h>
 #include <sys/wait.h>
 
+#include <compat_16.h>
+
 char *TCID = "setresuid03";
 
 uid_t neg_one = -1;
-uid_t inval_user = (USHRT_MAX - 2);
+uid_t inval_user;
 
 /* flag to tell parent if child passed or failed. */
 int flag = 0;
@@ -232,6 +234,10 @@ void setup(void)
        bin = *(getpwnam("bin"));
        bin_pw_uid = bin.pw_uid;
 
+       inval_user = GET_UNUSED_UID();
+       if (inval_user == -1)
+               tst_brkm(TBROK, NULL, "No free uid found");
+
        /* Pause if that option was specified
         * TEST_PAUSE contains the code to fork the test with the -i option.
         * You want to make sure you do this before you create your temporary
diff --git a/testcases/kernel/syscalls/utils/compat_gid.h 
b/testcases/kernel/syscalls/utils/compat_gid.h
index 82f8d84..1ce713b 100644
--- a/testcases/kernel/syscalls/utils/compat_gid.h
+++ b/testcases/kernel/syscalls/utils/compat_gid.h
@@ -48,4 +48,24 @@ GID_SIZE_CHECK(gid_t gid)
 
 #endif
 
+/* for 16-bit syscalls testing we can only
+ * use gids <= 0xFFFE */
+gid_t GET_UNUSED_GID(void)
+{
+       gid_t r;
+       r = tst_get_unused_gid();
+
+#ifdef TST_USE_COMPAT16_SYSCALL
+       if (!GID_SIZE_CHECK(r))
+               return -1;
+
+       /* kernel low2highgid() converts
+        * 0xFFFF to (gid_t)-1 */
+       if (r == (GID_T)-1)
+               return -1;
+#endif
+
+       return r;
+}
+
 #endif /* __SETGID_COMPAT_16_H__ */
diff --git a/testcases/kernel/syscalls/utils/compat_uid.h 
b/testcases/kernel/syscalls/utils/compat_uid.h
index 8200698..68896f4 100644
--- a/testcases/kernel/syscalls/utils/compat_uid.h
+++ b/testcases/kernel/syscalls/utils/compat_uid.h
@@ -48,4 +48,24 @@ UID_SIZE_CHECK(uid_t uid)
 
 #endif
 
+/* for 16-bit syscalls testing we can only
+ * use uids <= 0xFFFE */
+uid_t GET_UNUSED_UID(void)
+{
+       uid_t r;
+       r = tst_get_unused_uid();
+
+#ifdef TST_USE_COMPAT16_SYSCALL
+       if (!UID_SIZE_CHECK(r))
+               return -1;
+
+       /* kernel low2highuid() converts
+        * 0xFFFF to (uid_t)-1 */
+       if (r == (UID_T)-1)
+               return -1;
+#endif
+
+       return r;
+}
+
 #endif /* __SETUID_COMPAT_16_H__ */
-- 
1.7.1


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to