Re: [PATCH] fstatat: support NULL if AT_EMPTY_PATH

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <2043094.PYKUYFuaPT@cagnes>
Hi Paul,

> > FAIL: test-fstatat
> > ==================
> > 
> > Segmentation fault (core dumped)
> > FAIL test-fstatat (exit status: 139)
> > 
> > 
> > I reproduce it in Alpine Linux 3.24.1 (but not in 3.22 nor 3.20).
> 
> Thanks for the bug report. Unfortunately portal.cfarm.net lists only 
> Alpine 3.22 and 3.23.
> 
> Was this a crosscompile, or native? Was it x86-64 or some other 
> platform?

It was a native compilation on x86_64. Based on this Alpine Linux image:
https://dl-cdn.alpinelinux.org/alpine/v3.24/releases/x86_64/alpine-standard-3.24.1-x86_64.iso

> Is the build log public?

I'm attaching the logs (from my VM).

> > The backtrace is:
> >    test-fstatat.c:111
> >      -> musl/src/stat/fstatat.c:147
> >         -> musl/src/stat/fstatat.c:81
> > 
> > That line reads:
> >          if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
> 
> The backtrace suggests that REPLACE_FSTATAT was 0, because there is no 
> rentry for Gnulib's lib/fstatat.c.

Yes, REPLACE_FSTATAT was 0. (Looking in config.status.)

> However, REPLACE_FSTATAT should have 
> been 1 because the musl source code doesn't support AT_EMPTY_PATH with a 
> null pointer .
> 
> Can you verify whether fstatat is being replaced by checking that 
> m4/lib/sys/stat.h contains lines like the following?
> 
>    #if 1
>    # if 1
>    #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
>    #   undef fstatat
>    #   define fstatat rpl_fstatat
>    #  endif
>    _GL_FUNCDECL_RPL (fstatat, int,

No, it is like this:

    #if 1
    # if 0
    #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
    #   undef fstatat
    #   define fstatat rpl_fstatat
    #  endif
    _GL_FUNCDECL_RPL (fstatat, int,

> Can you look in config.log for lines like the following?
> 
>    ... checking whether fstatat+AT_EMPTY_PATH allows null file
>    ...
>    ... result: yes

Yes, config.log contains this. The 'conftest' program terminated with status 0.

> What happens when you compile and run the following program? What's the 
> tail of "strace ./a.out"? (This is the program 'configure' should be 
> running to see whether AT_EMPTY_PATH works with a null pointer.)
> 
>    #include <stddef.h>
>    #include <fcntl.h>
>    #include <sys/stat.h>
>    #ifndef AT_EMPTY_PATH
>    # define AT_EMPTY_PATH 0
>    #endif
>    #if __GLIBC__ && ! (2 < __GLIBC__ + (41 <= __GLIBC_MINOR__))
>     #error "glibc 2.40 and earlier can fail with null file"
>    #endif
> 
>    int
>    main (void)
>    {
>      struct stat st;
>      return
>        (AT_EMPTY_PATH
>         && fstatat (AT_FDCWD, NULL, &st, AT_EMPTY_PATH) < 0);
>    }

The tail of "strace ./a.out" is:

newfstatat(AT_FDCWD, NULL, {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}, AT_EMPTY_PATH) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

The tail of "ltrace ./a.out" is:

fstatat(0xffffff9c, 0, 0x7ffe8d831860, 4096)                                                       = 0
+++ exited (status 0) +++

The reason is that in this test program you pass fd = AT_FDCWD.
However, the crash in musl libc occurs only if fd>=0.

> What is the output of the shell command 'nm -g lib/libm4_a-fstatat.o'?

This file does not exist, because REPLACE_FSTATAT was 0.

Bruno
m4-2026-06-22-logs.tar.xz (application/x-xz-compressed-tar, 86.7 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.