@@ -66,6 +66,8 @@ static int
6666frame_setlineno (PyFrameObject * f , PyObject * p_new_lineno )
6767{
6868 int new_lineno = 0 ; /* The new value of f_lineno */
69+ long l_new_lineno ;
70+ int overflow ;
6971 int new_lasti = 0 ; /* The new value of f_lasti */
7072 int new_iblock = 0 ; /* The new value of f_iblock */
7173 unsigned char * code = NULL ; /* The bytecode for the frame... */
@@ -88,7 +90,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
8890 unsigned char setup_op = 0 ; /* (ditto) */
8991
9092 /* f_lineno must be an integer. */
91- if (!PyInt_CheckExact (p_new_lineno )) {
93+ if (!PyLong_CheckExact (p_new_lineno )) {
9294 PyErr_SetString (PyExc_ValueError ,
9395 "lineno must be an integer" );
9496 return -1 ;
@@ -104,7 +106,19 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
104106 }
105107
106108 /* Fail if the line comes before the start of the code block. */
107- new_lineno = (int ) PyLong_AsLong (p_new_lineno );
109+ l_new_lineno = PyLong_AsLongAndOverflow (p_new_lineno , & overflow );
110+ if (overflow
111+ #if SIZEOF_LONG > SIZEOF_INT
112+ || l_new_lineno > INT_MAX
113+ || l_new_lineno < INT_MIN
114+ #endif
115+ ) {
116+ PyErr_SetString (PyExc_ValueError ,
117+ "lineno out of range" );
118+ return -1 ;
119+ }
120+ new_lineno = (int )l_new_lineno ;
121+
108122 if (new_lineno < f -> f_code -> co_firstlineno ) {
109123 PyErr_Format (PyExc_ValueError ,
110124 "line %d comes before the current code block" ,
0 commit comments