[3.13] gh-120155: Fix Coverity issue in parse_string() (GH-120997) (#121005)

gh-120155: Fix Coverity issue in parse_string() (GH-120997)
(cherry picked from commit 769aea3329)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2024-06-25 19:40:05 +02:00 committed by GitHub
parent f4f8a714b5
commit 571cefd8c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View 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;