]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-120155: Fix Coverity issue in parse_string() (GH-120997) (#121005)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 25 Jun 2024 17:40:05 +0000 (19:40 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2024 17:40:05 +0000 (19:40 +0200)
gh-120155: Fix Coverity issue in parse_string() (GH-120997)
(cherry picked from commit 769aea332940f03c3e5b1ad9badd6635c1ac992a)

Co-authored-by: Victor Stinner <vstinner@python.org>
Parser/string_parser.c

index bacfd815441110944676661fe5e21c138dcc1b3b..93ad92b823581e0ec250b226e263541b007cb562 100644 (file)
@@ -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;