Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-35714: Reject null characters in struct format strings #16928

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

Merged

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Oct 26, 2019

struct.error is now raised if there is a null character in a struct
format string.

https://bugs.python.org/issue35714

struct.error is now raised if there is a null character in a struct
format string.
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -652,6 +652,13 @@ def test_format_attr(self):
s2 = struct.Struct(s.format.encode())
self.assertEqual(s2.format, s.format)

def test_issue35714(self):
# Embedded null characters should not be allowed in format strings.
for s in '\0', '\144\u0064\000xf', 'd\0d', '>ih\0', '=Q\0\0':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between all these cases? Why they are needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The embedded null is located at different positions of the string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why it is handled differently depending on the position?

I would test with '\0', '2\0i' and b'\0'.

@csabella csabella requested a review from serhiy-storchaka May 23, 2020 18:00
@serhiy-storchaka serhiy-storchaka added needs backport to 3.6 needs backport to 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels May 25, 2020
@serhiy-storchaka serhiy-storchaka merged commit 3f59b55 into python:master May 25, 2020
@miss-islington
Copy link
Contributor

Thanks @ZackerySpytz for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7, 3.8, 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2020
…16928)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)

Co-authored-by: Zackery Spytz <[email protected]>
@bedevere-bot
Copy link

GH-20373 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label May 25, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2020
…16928)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)

Co-authored-by: Zackery Spytz <[email protected]>
@bedevere-bot
Copy link

GH-20374 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2020
…16928)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)

Co-authored-by: Zackery Spytz <[email protected]>
@bedevere-bot
Copy link

GH-20375 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2020
…16928)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)

Co-authored-by: Zackery Spytz <[email protected]>
@bedevere-bot
Copy link

GH-20376 is a backport of this pull request to the 3.6 branch.

miss-islington added a commit that referenced this pull request May 26, 2020
struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)

Co-authored-by: Zackery Spytz <[email protected]>
ZackerySpytz added a commit to ZackerySpytz/cpython that referenced this pull request May 26, 2020
…honGH-16928)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)

Co-authored-by: Zackery Spytz <[email protected]>
serhiy-storchaka pushed a commit that referenced this pull request May 26, 2020
…16928) (GH-20419)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 26, 2020
…honGH-16928) (pythonGH-20419)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)
(cherry picked from commit 5ff5edf)

Co-authored-by: Zackery Spytz <[email protected]>
miss-islington added a commit that referenced this pull request May 26, 2020
…16928) (GH-20419)

struct.error is now raised if there is a null character in a struct
format string.
(cherry picked from commit 3f59b55)
(cherry picked from commit 5ff5edf)

Co-authored-by: Zackery Spytz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants