1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

libio: Synthesize ESPIPE error if lseek returns 0 after reading bytes

This is required so that fclose, when trying to seek to the right
position after filling the input buffer, does not fail with EINVAL.
This fclose code path only ignores ESPIPE errors.

Reported by Petr Pisar on
<https://bugzilla.redhat.com/show_bug.cgi?id=2358265>.

Fixes commit be6818be31 ("Make fclose
seek input file to right offset (bug 12724)").

Reviewed-by: Frédéric Bérat <fberat@redhat.com>
This commit is contained in:
Florian Weimer
2025-04-08 18:38:38 +02:00
parent de14f1959e
commit 7b47b3dd21
3 changed files with 61 additions and 0 deletions

View File

@@ -928,6 +928,16 @@ do_ftell (FILE *fp)
if (result == EOF)
return result;
if (result == 0 && offset < 0)
{
/* This happens for some character devices that always report
file offset 0 even after some data has been read (instead of
failing with ESPIPE). The fclose path ignores this
error. */
__set_errno (ESPIPE);
return EOF;
}
result += offset;
if (result < 0)