PyInt_FromString(), int_repr(), int_oct(), int_hex(): Conversion of
sprintf() to PyOS_snprintf() for buffer overrun avoidance.
This commit is contained in:
parent
af8aef9ee2
commit
6197509f24
|
@ -198,12 +198,14 @@ PyInt_FromString(char *s, char **pend, int base)
|
||||||
end++;
|
end++;
|
||||||
if (*end != '\0') {
|
if (*end != '\0') {
|
||||||
bad:
|
bad:
|
||||||
sprintf(buffer, "invalid literal for int(): %.200s", s);
|
PyOS_snprintf(buffer, sizeof(buffer),
|
||||||
|
"invalid literal for int(): %.200s", s);
|
||||||
PyErr_SetString(PyExc_ValueError, buffer);
|
PyErr_SetString(PyExc_ValueError, buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (errno != 0) {
|
else if (errno != 0) {
|
||||||
sprintf(buffer, "int() literal too large: %.200s", s);
|
PyOS_snprintf(buffer, sizeof(buffer),
|
||||||
|
"int() literal too large: %.200s", s);
|
||||||
PyErr_SetString(PyExc_ValueError, buffer);
|
PyErr_SetString(PyExc_ValueError, buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +259,7 @@ static PyObject *
|
||||||
int_repr(PyIntObject *v)
|
int_repr(PyIntObject *v)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
sprintf(buf, "%ld", v->ob_ival);
|
PyOS_snprintf(buf, sizeof(buf), "%ld", v->ob_ival);
|
||||||
return PyString_FromString(buf);
|
return PyString_FromString(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -820,7 +822,7 @@ int_oct(PyIntObject *v)
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
strcpy(buf, "0");
|
strcpy(buf, "0");
|
||||||
else
|
else
|
||||||
sprintf(buf, "0%lo", x);
|
PyOS_snprintf(buf, sizeof(buf), "0%lo", x);
|
||||||
return PyString_FromString(buf);
|
return PyString_FromString(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,7 +831,7 @@ int_hex(PyIntObject *v)
|
||||||
{
|
{
|
||||||
char buf[100];
|
char buf[100];
|
||||||
long x = v -> ob_ival;
|
long x = v -> ob_ival;
|
||||||
sprintf(buf, "0x%lx", x);
|
PyOS_snprintf(buf, sizeof(buf), "0x%lx", x);
|
||||||
return PyString_FromString(buf);
|
return PyString_FromString(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue