From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:03:40 +0000 (-0700) Subject: gh-96678: Fix UB of null pointer arithmetic (GH-96782) X-Git-Tag: v3.11.1~488 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f2d7fa88390502fa408b8f1e1ad1b6d23a04c48a;p=thirdparty%2FPython%2Fcpython.git gh-96678: Fix UB of null pointer arithmetic (GH-96782) Automerge-Triggered-By: GH:pablogsal (cherry picked from commit 81e36f350b75d2ed2668825f7df6e059b57f859c) Co-authored-by: Matthias Görgens --- diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-13-12-06-46.gh-issue-96678.NqGFyb.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-13-12-06-46.gh-issue-96678.NqGFyb.rst new file mode 100644 index 000000000000..bdd33c8d2ca9 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-13-12-06-46.gh-issue-96678.NqGFyb.rst @@ -0,0 +1 @@ +Fix undefined behaviour in C code of null pointer arithmetic. diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 8d9fbf5cf959..a5cfb659b430 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1542,7 +1542,7 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end) } while (c == ' ' || c == '\t' || c == '\014'); /* Set start of current token */ - tok->start = tok->cur - 1; + tok->start = tok->cur == NULL ? NULL : tok->cur - 1; /* Skip comment, unless it's a type comment */ if (c == '#') {