1
0
mirror of https://github.com/python/cpython synced 2024-07-01 09:49:18 +00:00

gh-120155: Fix Coverity issue in parse_string() (#120997)

This commit is contained in:
Victor Stinner 2024-06-25 18:53:24 +02:00 committed by GitHub
parent 2d3187bf20
commit 769aea3329
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -229,9 +229,14 @@ _PyPegen_parse_string(Parser *p, Token *t)
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return NULL; return NULL;
} }
/* Skip the leading quote char. */ /* Skip the leading quote char. */
s++; s++;
len = strlen(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) { if (len > INT_MAX) {
PyErr_SetString(PyExc_OverflowError, "string to parse is too long"); PyErr_SetString(PyExc_OverflowError, "string to parse is too long");
return NULL; return NULL;