bug-gnulib
[Top][All Lists]
Advanced

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

Re: yesno module consumes too much input


From: Jim Meyering
Subject: Re: yesno module consumes too much input
Date: Fri, 17 Aug 2007 22:50:57 +0200

Eric Blake-1 <address@hidden> wrote:
> The yesno module has a problem on platforms where exit()
> does not implicitly flush seekable input streams (this behavior
> of exit() is contrary to POSIX, but glibc behaves this way,
> and Ulrich was unwilling to fix the glibc bug [1]).  Basically,
> because the yesno module consumes input from stdin, if
> the application does not restore the offset of the underlying
> fd to the next unread byte prior to a successful exit, then
> data is lost from subsequent applications that also read
> from the file descriptor.
>
> For an example of the bug, try this on Linux (tested
> with glibc 2.3):
>
> $ touch a b
> $ echo 'n
> y' > blah
> $ (export LC_ALL=C; mv -vi a b; mv -vi a b) < blah
> mv: overwrite `b'? mv: overwrite `b'?
> $ echo $?
> 0
> $ ls ?
> a  b
>
> contrasted to Solaris or cygwin (where exit() already
> takes care of flushing seekable stdin):
>
> $ touch a b
> $ echo 'n
> y' > blah
> $ (export LC_ALL=C; mv -vi a b; mv -vi a b) < blah
> mv: overwrite `b'? mv: overwrite `b'? `a' -> `b'
> $ echo $?
> 0
> $ ls ?
> b
>
> Basically, on buggy platforms, the first mv did not reset
> the file pointer to the unread line "y", so the second mv
> saw EOF instead of the affirmative response.  The end
> result was a violation of POSIX semantics on Linux.
>
> The closein module is capable of resolving this problem.
> However, rather than fix all of the affected applications
> one-by-one (the list includes, but is not limited to,
> coreutils' cp, ln, mv, rm, and remove; and findutils' find),
> it would be nicer to fix this just once in yesno.  OK to
> apply the patch below?
>
> [1] http://sources.redhat.com/bugzilla/show_bug.cgi?id=3746
>
>
> 2007-08-17  Eric Blake  <address@hidden>
>
>       Don't consume too much input when stdin is seekable.
>       * lib/yesno.c (yesno): Flush seekable stdin.
>       * modules/yesno (Depends-on): Add fflush.

That looks fine to me.
However, a change like this requires at least one test,
either in gnulib or in coreutils (or both!) to exercise it.
You're welcome to commit it, but please also add a test or two.




reply via email to

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