Bug 24940 - fgets get skipped after EOF
Summary: fgets get skipped after EOF
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: 2.29
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-27 08:57 UTC by pascal.liedtke
Modified: 2019-08-27 09:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pascal.liedtke 2019-08-27 08:57:51 UTC
Here a sample code:

#include <stdio.h>
int main() {
    char input[80];
    while (fgets(input, 80, stdin) != NULL) {
        // nop
    }
    fgets(input, 80, stdin);
    printf("%s\n", input);
    return 0;
}

After sending EOF to exit the loop, the second fgets returns immediately return NULL, no second input possible. Compiling on 2.27 works as expected. Compiling on a 2.27 system with -static and executing on a 2.29 System also works.

I have no more glibc versions to check more. Only can say bugged on 2.29, works on 2.27.
Comment 1 Andreas Schwab 2019-08-27 09:16:42 UTC
This is correct behaviour.  EOF is supposed to be sticky, see commit 2cc7bad0ae.