]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-120155: Fix Coverity issue in parse_string() (GH-120997) (#121006)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 25 Jun 2024 17:40:08 +0000 (19:40 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2024 17:40:08 +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 65c320c2173e924c80d38bbd8ea6334f714f9fd2..164f715e153eca9c58964dd0459e7b335439a550 100644 (file)
@@ -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;