bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Test suite failure in clean chroot of ArchLinux


From: Letu Ren
Subject: Re: Test suite failure in clean chroot of ArchLinux
Date: Mon, 20 Jun 2022 05:07:29 +0800

> That's not a problem; we can live with that.
>
> But there's no need to follow up in private email; please always keep the
> list in CC.

Sorry for that private email. I'm not familiar with mailing lists and
just click 'reply' in gmail. I'll pay attention to this issue next
time.

> I don't like the *scanf family of functions. For a simple parsing function
> like strtoul(), I can understand for which inputs it behaves in which ways
> (empty input? not integer syntax? leading minus sign? unsigned integer
> overflow?); for fscanf there are just too many cases, I can't wrap my head
> around.
>
> So I'm committing this instead.
>
>
> 2022-06-19  Bruno Haible  <bruno@clisp.org>
>
>         getlogin, getlogin_r tests: Really avoid test failure.
>         Reported by Letu Ren <fantasquex@gmail.com> in
>         <https://lists.gnu.org/archive/html/bug-gnulib/2022-06/msg00037.html>.
>         * tests/test-getlogin.h (test_getlogin_result): Parse the contents of
>         /proc/self/loginuid as an unsigned integer.
>
> diff --git a/tests/test-getlogin.h b/tests/test-getlogin.h
> index 3489e3e03d..fcc7741f12 100644
> --- a/tests/test-getlogin.h
> +++ b/tests/test-getlogin.h
> @@ -51,16 +51,25 @@ test_getlogin_result (const char *buf, int err)
>  #if defined __linux__
>        /* On Linux, it is possible to set up a chroot environment in such a 
> way
>           that stdin is connected to a tty and nervertheless 
> /proc/self/loginuid
> -         contains "-1".  In this situation, getlogin() and getlogin_r() fail;
> -         this is expected.  */
> +         contains the value (uid_t)(-1).  In this situation, getlogin() and
> +         getlogin_r() fail; this is expected.  */
>        bool loginuid_undefined = false;
> -      /* Does the special file /proc/self/loginuid contain "-1"?  */
> +      /* Does the special file /proc/self/loginuid contain the value
> +         (uid_t)(-1)?  */
>        FILE *fp = fopen ("/proc/self/loginuid", "r");
>        if (fp != NULL)
>          {
> -          char buf[3];
> -          loginuid_undefined =
> -            (fread (buf, 1, 3, fp) == 2 && buf[0] == '-' && buf[1] == '1');
> +          char buf[21];
> +          size_t n = fread (buf, 1, sizeof buf, fp);
> +          if (n > 0 && n < sizeof buf)
> +            {
> +              buf[n] = '\0';
> +              errno = 0;
> +              char *endptr;
> +              unsigned long value = strtoul (buf, &endptr, 10);
> +              if (*endptr == '\0' && errno == 0)
> +                loginuid_undefined = ((uid_t) value == (uid_t)(-1));
> +            }
>            fclose (fp);
>          }
>        if (loginuid_undefined)

I noticed your recent commit and backported it to test with coreutils
9.1. And it worked as expected. This issue has been resolved
successfully. Cheers! Thanks for your work on the patch. I'll report
to ArchLinux to add this to help with reproducible build. Hope this
patch will be included in the next version of coreutils.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]