On Mon, Oct 27, 2025 at 02:51:57PM -0700, Collin Funk wrote:

> >> I'll bring it up on the libc-alpha list later today. Thankfully it was
> >> caught on Rawhide before a new glibc release.
> >
> > https://www.austingroupbugs.net/view.php?id=1953 tracks the request
> > for clarification from the Austin Group (may take several weeks).
> 
> Great! I was hoping you would handle that, since I am less familiar with
> the Austin Group bug reporting format.
> 
> I'll reference it in my libc-alpha mail in case we want to wait for
> feedback there.

The Austin Group visited the proposal today, and went with option 1,
adding the following wording to the standard:

    If the return value is -1, the contents of *lineptr are indeterminate.

which means that glibc's behavior both before the patch (returning -1
without changing *lineptr when the file is empty) and after the patch
(unconditionally changing *lineptr to the empty string when returning
-1 at EOF, thereby hiding the last line of the file previously read)
would be in compliance with the updated POSIX wording.  The
implication is that the behavior I pointed out in nbdkit assuming the
last line would still be in the buffer is non-portable to updated
POSIX wording, regardless of whether glibc keeps the new behavior,
reverts to the old behavior, or versions the getdelim/getline symbols
to preserve back-compat to programs linked against older versions of
glibc.

glibc is, of course, welcome to decide if it wants to document a
particular behavior as well-defined even where POSIX says a portable
program must assume indeterminate contents.  If glibc wants to define
what POSIX left undefined, then gnulib should ensure that extra
guarantee even on platforms that provide a native getdelim with
behavior that differs from glibc.

For what it's worth, I also inspected the BSD source code, which
appears to blindly truncate the buffer when EOF is encountered without
data, which matches glibc's new behavior:
https://github.com/freebsd/freebsd-src/blob/main/lib/libc/stdio/getdelim.c

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to