@@ -2095,8 +2095,7 @@ int_from_string(v)
20952095 long x ;
20962096 char buffer [256 ]; /* For errors */
20972097
2098- if (!PyArg_Parse (v , "s" , & s ))
2099- return NULL ;
2098+ s = PyString_AS_STRING (v );
21002099 while (* s && isspace (Py_CHARMASK (* s )))
21012100 s ++ ;
21022101 if (s [0 ] == '\0' ) {
@@ -2112,6 +2111,11 @@ int_from_string(v)
21122111 PyErr_SetString (PyExc_ValueError , buffer );
21132112 return NULL ;
21142113 }
2114+ else if (end - s != PyString_GET_SIZE (v )) {
2115+ PyErr_SetString (PyExc_ValueError ,
2116+ "null byte in argument for int()" );
2117+ return NULL ;
2118+ }
21152119 else if (errno != 0 ) {
21162120 sprintf (buffer , "int() literal too large: %.200s" , s );
21172121 PyErr_SetString (PyExc_ValueError , buffer );
@@ -2128,9 +2132,7 @@ long_from_string(v)
21282132 PyObject * x ;
21292133 char buffer [256 ]; /* For errors */
21302134
2131- if (!PyArg_Parse (v , "s" , & s ))
2132- return NULL ;
2133-
2135+ s = PyString_AS_STRING (v );
21342136 while (* s && isspace (Py_CHARMASK (* s )))
21352137 s ++ ;
21362138 if (s [0 ] == '\0' ) {
@@ -2148,6 +2150,11 @@ long_from_string(v)
21482150 Py_DECREF (x );
21492151 return NULL ;
21502152 }
2153+ else if (end - s != PyString_GET_SIZE (v )) {
2154+ PyErr_SetString (PyExc_ValueError ,
2155+ "null byte in argument for float()" );
2156+ return NULL ;
2157+ }
21512158 return x ;
21522159}
21532160
@@ -2160,8 +2167,7 @@ float_from_string(v)
21602167 double x ;
21612168 char buffer [256 ]; /* For errors */
21622169
2163- if (!PyArg_Parse (v , "s" , & s ))
2164- return NULL ;
2170+ s = PyString_AS_STRING (v );
21652171 while (* s && isspace (Py_CHARMASK (* s )))
21662172 s ++ ;
21672173 if (s [0 ] == '\0' ) {
@@ -2179,6 +2185,11 @@ float_from_string(v)
21792185 PyErr_SetString (PyExc_ValueError , buffer );
21802186 return NULL ;
21812187 }
2188+ else if (end - s != PyString_GET_SIZE (v )) {
2189+ PyErr_SetString (PyExc_ValueError ,
2190+ "null byte in argument for float()" );
2191+ return NULL ;
2192+ }
21822193 else if (errno != 0 ) {
21832194 sprintf (buffer , "float() literal too large: %.200s" , s );
21842195 PyErr_SetString (PyExc_ValueError , buffer );
0 commit comments