]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120155: Fix Coverity issue in parse_string() (#120997)
authorVictor Stinner <vstinner@python.org>
Tue, 25 Jun 2024 16:53:24 +0000 (18:53 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2024 16:53:24 +0000 (17:53 +0100)
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;