Commit 00aebabc authored by Miss Islington (bot)'s avatar Miss Islington (bot) Committed by GitHub

closes bpo-34400: Fix undefined behavior in parsetok(). (GH-4439)


Avoid undefined pointer arithmetic with NULL.
(cherry picked from commit 7c4ab2af)
Co-authored-by: default avatarZackery Spytz <zspytz@gmail.com>
parent 1f34aece
Fix undefined behavior in parsetok.c. Patch by Zackery Spytz.
...@@ -176,7 +176,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, ...@@ -176,7 +176,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
} }
else else
started = 1; started = 1;
len = b - a; /* XXX this may compute NULL - NULL */ len = (a != NULL && b != NULL) ? b - a : 0;
str = (char *) PyObject_MALLOC(len + 1); str = (char *) PyObject_MALLOC(len + 1);
if (str == NULL) { if (str == NULL) {
fprintf(stderr, "no mem for next token\n"); fprintf(stderr, "no mem for next token\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment