Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that fread() doesn't set EOF early #598

Merged
merged 1 commit into from
Nov 5, 2023
Merged

Ensure that fread() doesn't set EOF early #598

merged 1 commit into from
Nov 5, 2023

Conversation

gperciva
Copy link
Member

@gperciva gperciva commented Nov 5, 2023

No description provided.

This is only relevant with libc implementations of fread() which violate
the standard.

1) Suppose that fread() reads an entire file into its internal buffer
   (say, 64kb).

2) Then it returns a smaller value (say, 8192) which we requested.

3) But then it sets the end-of-file indicator because it's loaded the
   whole file into its internal buffer.
   *** ^ that's not how fread() is supposed to work. ***

4) Suppose that there's no end-of-line character at the end of the
   8192-byte buffer.

5) In that case, we would write '\0' to one past the end of buff.

Step 3 violates the standard; fread() should only set the end-of-file if
it returns less than we requested.

Reported by:	Rasmus Villemoes
Bug bounty:	$5
@cperciva cperciva merged commit 5b5cfef into master Nov 5, 2023
2 checks passed
@gperciva gperciva deleted the bounties branch November 5, 2023 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants