[New-bugs-announce] [issue25817] modsupport: 'countformat' does not handle strings without bracket levels correctly
Myron Walker
report at bugs.python.org
Mon Dec 7 16:55:15 EST 2015
New submission from Myron Walker:
'countformat' does not appear to be handling the case where a format string is passed with no parenthesis or brackets correctly. Here is an
example of a usage that might cause issues from typedobject.c:
static PyObject*
slot_sq_slice(PyObject *self, Py_ssize_t i, Py_ssize_t j)
{
static PyObject *getslice_str;
if (PyErr_WarnPy3k("in 3.x, __getslice__ has been removed; "
"use __getitem__", 1) < 0)
return NULL;
return call_method(self, "__getslice__", &getslice_str,
"nn", i, j); <<<<<<< Maybe Bad Format Str <<<<<<<
}
The format string "nn" does not have any level markers so when it gets
processed by 'countformat' the count will be incremented 2 times by the
'default' case but when the end of the string is reached and the NULL character is processed bay "case '\0':". The function will ignore the count variable and just return -1 anyway. The error created is unmatched paren in format but 'level' is never checked to see if a paren
was even hit to begin with.
It might be that the case should be changed to look at level before assuming a error condition if strings are supposed to be processed as the one in the example above. case '\0' should probably be doing something like:
case '\0':
if (level > 0) { // Check If Level Was Incremented
/* Premature end */
PyErr_SetString(PyExc_SystemError,
"unmatched paren in format");
return -1;
}
break;
----------
components: Interpreter Core
messages: 256075
nosy: Myron Walker
priority: normal
severity: normal
status: open
title: modsupport: 'countformat' does not handle strings without bracket levels correctly
type: behavior
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25817>
_______________________________________
More information about the New-bugs-announce
mailing list