summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-07-26 08:03:10 (GMT)
committerGeorg Brandl <georg@python.org>2006-07-26 08:03:10 (GMT)
commit5f135787ec4040bfbeb16f2944086028635151db (patch)
treea7db166102d100e0d6e77fca48573772b88fb8ce /Python
parent0619a329e822641dff088d9141a7885da882369c (diff)
downloadcpython-5f135787ec4040bfbeb16f2944086028635151db.zip
cpython-5f135787ec4040bfbeb16f2944086028635151db.tar.gz
cpython-5f135787ec4040bfbeb16f2944086028635151db.tar.bz2
Part of bug #1523610: fix miscalculation of buffer length.
Also add a guard against NULL in converttuple and add a test case (that previously would have crashed).
Diffstat (limited to 'Python')
-rw-r--r--Python/getargs.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 1552790..508055e 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -351,8 +351,8 @@ seterror(int iarg, const char *msg, int *levels, const char *fname,
"argument %d", iarg);
i = 0;
p += strlen(p);
- while (levels[i] > 0 && (int)(p-buf) < 220) {
- PyOS_snprintf(p, sizeof(buf) - (buf - p),
+ while (levels[i] > 0 && i < 32 && (int)(p-buf) < 220) {
+ PyOS_snprintf(p, sizeof(buf) - (p - buf),
", item %d", levels[i]-1);
p += strlen(p);
i++;
@@ -439,6 +439,13 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
char *msg;
PyObject *item;
item = PySequence_GetItem(arg, i);
+ if (item == NULL) {
+ PyErr_Clear();
+ levels[0] = i+1;
+ levels[1] = 0;
+ strncpy(msgbuf, "is not retrievable", bufsize);
+ return msgbuf;
+ }
msg = convertitem(item, &format, p_va, flags, levels+1,
msgbuf, bufsize, freelist);
/* PySequence_GetItem calls tp->sq_item, which INCREFs */
@@ -1509,6 +1516,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
else {
msg = skipitem(&format, p_va, flags);
if (msg) {
+ levels[0] = 0;
seterror(i+1, msg, levels, fname, message);
return cleanreturn(0, freelist);
}