[LTP] [PATCH 2/2] getuid/getuid03: Convert to new API

Cyril Hrubis chrubis@suse.cz
Wed Nov 10 12:06:17 CET 2021


Hi!
> +static void verify_getuid(void)
>  {
>  	struct passwd *pwent;
> -	int lc;
>  	uid_t uid;
> 
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> +	TEST(GETUID());
> 
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +	if (TST_RET == -1)
> +		tst_brk(TBROK | TTERRNO, "getuid failed");
> 
> -		tst_count = 0;
> +	uid = getuid();

We have the return from getuid() stored in TST_RET at this point, why do
we call it again here?

> +	pwent = getpwuid(uid);
> 
> -		TEST(GETUID(cleanup));
> +	if (pwent == NULL)
> +		tst_res(TFAIL | TERRNO, "getpwuid failed");

I guess that we should exit the test here, otherwise it will segfault,
so this should be tst_brk(TBROK | TERRNO, ...);

Also I do wonder if comparing the return from getuid() to the return
from getpwuid(getguid()) makes any sense. We lookup password entry given
an uid then check that the password entry uid matches. That sounds like
a test for getpwuid() more than anything else.

I wonder what would be better check. We should rather than this check
the return value against the /proc/self/status where all the UIDs are
listed as well.


-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list