-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-140594: Fix buffer overflow when feeding NULL bytes to PyOS_StdioReadline
#140910
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
base: main
Are you sure you want to change the base?
Changes from 13 commits
0463fb7
71d79ca
42fdcfb
b09a4c8
976dedb
3f4a6be
2392f76
cfd56e6
2647f02
11912ec
010a482
9dbeba9
a982737
6f83dc8
6ffaace
43025bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix a buffer overflow when a single NULL character is read from the standard input. | ||
| Patch by Shamil Abdulaev. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -344,7 +344,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) | |||||
| break; | ||||||
| } | ||||||
| n += strlen(p + n); | ||||||
| } while (p[n-1] != '\n'); | ||||||
ashm-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } while (n == 0 || p[n-1] != '\n'); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to stop the loop if n==0.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then input like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure which behavior is the correct behavior honestly. I suppose that you should call readline again to read
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds worth it to add a test at least.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then behavior will be different if string starts with NUL byte or has it in the middle. I think we should document this difference.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have this conversation here: #140910 (comment). |
||||||
|
|
||||||
| pr = (char *)PyMem_RawRealloc(p, n+1); | ||||||
ashm-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| if (pr == NULL) { | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.