From: Victor Stinner Date: Tue, 25 Jun 2024 16:53:24 +0000 (+0200) Subject: gh-120155: Fix Coverity issue in parse_string() (#120997) X-Git-Tag: v3.14.0a1~1331 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=769aea332940f03c3e5b1ad9badd6635c1ac992a;p=thirdparty%2FPython%2Fcpython.git gh-120155: Fix Coverity issue in parse_string() (#120997) --- diff --git a/Parser/string_parser.c b/Parser/string_parser.c index bacfd8154411..93ad92b82358 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -229,9 +229,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;