From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:40:08 +0000 (+0200) Subject: [3.12] gh-120155: Fix Coverity issue in parse_string() (GH-120997) (#121006) X-Git-Tag: v3.12.5~167 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5290e405c171dbf541b1cd8549d69d53d04a6bc0;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-120155: Fix Coverity issue in parse_string() (GH-120997) (#121006) gh-120155: Fix Coverity issue in parse_string() (GH-120997) (cherry picked from commit 769aea332940f03c3e5b1ad9badd6635c1ac992a) Co-authored-by: Victor Stinner --- diff --git a/Parser/string_parser.c b/Parser/string_parser.c index 65c320c2173e..164f715e153e 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -226,9 +226,14 @@ _PyPegen_parse_string(Parser *p, Token *t) PyErr_BadInternalCall(); return NULL; } + /* Skip the leading quote char. */ s++; len = strlen(s); + // gh-120155: 's' contains at least the trailing quote, + // so the code '--len' below is safe. + assert(len >= 1); + if (len > INT_MAX) { PyErr_SetString(PyExc_OverflowError, "string to parse is too long"); return NULL;