[Bug 4067] New: configure assumes BROKEN_ONE_BYTE_DIRENT_D_NAME when cross compiling

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Thu Nov 26 22:29:39 AEDT 2026


https://bugzilla.mindrot.org/show_bug.cgi?id=4067

            Bug ID: 4067
           Summary: configure assumes BROKEN_ONE_BYTE_DIRENT_D_NAME when
                    cross compiling
           Product: Portable OpenSSH
           Version: -current
          Hardware: PPC
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P5
         Component: Build system
          Assignee: unassigned-bugs at mindrot.org
          Reporter: keragez at gmail.com

Created attachment 4038
  --> https://bugzilla.mindrot.org/attachment.cgi?id=4038&action=edit
patch for dirent dname size detection

The "whether struct dirent allocates space for d_name" check in
configure.ac is an AC_RUN_IFELSE test. When cross compiling it can't
be run, and configure falls back to defining
BROKEN_ONE_BYTE_DIRENT_D_NAME (the Solaris layout) for every target:

  checking whether struct dirent allocates space for d_name...
  configure: WARNING: cross compiling: assuming
BROKEN_ONE_BYTE_DIRENT_D_NAME

On glibc, d_name is char[256], so a cross build compiles the Solaris
branch of fudge_readdir() in sftp-glob.c, which passes MAXPATHLEN as
the size of d_name:

  strlcpy(ret->d_name, od->dir[od->offset++]->filename, MAXPATHLEN);

Since glibc 2.38 declares strlcpy() with an access attribute and a
fortified wrapper, GCC reports:

  sftp-glob.c: In function 'fudge_readdir':
  sftp-glob.c:83:9: warning: 'strlcpy' writing 4096 bytes into a region
  of size 256 overflows the destination [-Wstringop-overflow=]

The workaround is harmless at runtime because buf reserves MAXPATHLEN
bytes behind the struct. Even so, Linux shouldn't be compiling it, and
the write is formally past the end of d_name.

Steps to reproduce:

  Cross compile for any glibc Linux target, e.g.
    ./configure --build=x86_64-pc-linux-gnu --host=powerpc-linux-gnu
...
  Configure prints the warning above, config.h defines
  BROKEN_ONE_BYTE_DIRENT_D_NAME, and building sftp-glob.c gives
  -Wstringop-overflow with glibc >= 2.38.

Proposed fix (patch attached, also at
https://github.com/keragez/openssh-portable/tree/fix-dirent-dname-cross):

sizeof(d.d_name) is a compile-time constant, so test it with
AC_COMPILE_IFELSE and drop the cross-compiling guess:

  struct dirent d;
  static int d_name_fits[sizeof(d.d_name) > sizeof(char) ? 1 : -1];

Native builds get the same answer as before. Cross builds now get the
correct one. Tested native glibc (yes), a stub <dirent.h> with
char d_name[1] (no), forced cross configure (yes, no warning), and a
full cross build for powerpc-e500v2-linux-gnu with glibc 2.42 and
GCC 14.3 (yes, the sftp-glob.c warning is gone).

GitHub CI on my fork:   
https://github.com/keragez/openssh-portable/actions/runs/45658571568
GitHub CI VM on my fork:
https://github.com/keragez/openssh-portable/actions/runs/45658571566

Werror jobs fail on ssh-keygen.c:1375 (-Wmaybe-uninitialized),
introduced upstream by 4c3e65f18 and unrelated to this change.

Found while cleaning up compiler warnings in a cross build for 32-bit
PowerPC (e500v2). Analysis and the patch were done with the help of
Claude (Opus 5.5); I reviewed the change and verified it on the cross
build as described above.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


More information about the openssh-bugs mailing list