@@ -1483,6 +1483,9 @@ element_getattro(ElementObject* self, PyObject* nameobj)
14831483
14841484 if (PyUnicode_Check (nameobj ))
14851485 name = _PyUnicode_AsString (nameobj );
1486+
1487+ if (name == NULL )
1488+ return NULL ;
14861489
14871490 /* handle common attributes first */
14881491 if (strcmp (name , "tag" ) == 0 ) {
@@ -2139,7 +2142,7 @@ expat_set_error(const char* message, int line, int column)
21392142 PyObject * position ;
21402143 char buffer [256 ];
21412144
2142- sprintf (buffer , "%s : line %d, column %d" , message , line , column );
2145+ sprintf (buffer , "%.100s : line %d, column %d" , message , line , column );
21432146
21442147 error = PyObject_CallFunction (elementtree_parseerror_obj , "s" , buffer );
21452148 if (!error )
@@ -2194,8 +2197,8 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
21942197 Py_XDECREF (res );
21952198 } else if (!PyErr_Occurred ()) {
21962199 /* Report the first error, not the last */
2197- char message [128 ];
2198- sprintf (message , "undefined entity &%.100s;" , _PyUnicode_AsString ( key ) );
2200+ char message [128 ] = "undefined entity " ;
2201+ strncat (message , data_in , data_len < 100 ? data_len : 100 );
21992202 expat_set_error (
22002203 message ,
22012204 EXPAT (GetErrorLineNumber )(self -> parser ),
@@ -2796,29 +2799,25 @@ static PyMethodDef xmlparser_methods[] = {
27962799static PyObject *
27972800xmlparser_getattro (XMLParserObject * self , PyObject * nameobj )
27982801{
2799- PyObject * res ;
2800- char * name = "" ;
2801-
2802- if (PyUnicode_Check (nameobj ))
2803- name = _PyUnicode_AsString (nameobj );
2804-
2805- PyErr_Clear ();
2806-
2807- if (strcmp (name , "entity" ) == 0 )
2808- res = self -> entity ;
2809- else if (strcmp (name , "target" ) == 0 )
2810- res = self -> target ;
2811- else if (strcmp (name , "version" ) == 0 ) {
2812- char buffer [100 ];
2813- sprintf (buffer , "Expat %d.%d.%d" , XML_MAJOR_VERSION ,
2802+ if (PyUnicode_Check (nameobj )) {
2803+ PyObject * res ;
2804+ if (PyUnicode_CompareWithASCIIString (nameobj , "entity" ) == 0 )
2805+ res = self -> entity ;
2806+ else if (PyUnicode_CompareWithASCIIString (nameobj , "target" ) == 0 )
2807+ res = self -> target ;
2808+ else if (PyUnicode_CompareWithASCIIString (nameobj , "version" ) == 0 ) {
2809+ return PyUnicode_FromFormat (
2810+ "Expat %d.%d.%d" , XML_MAJOR_VERSION ,
28142811 XML_MINOR_VERSION , XML_MICRO_VERSION );
2815- return PyUnicode_DecodeUTF8 (buffer , strlen (buffer ), "strict" );
2816- } else {
2817- return PyObject_GenericGetAttr ((PyObject * ) self , nameobj );
2818- }
2812+ }
2813+ else
2814+ goto generic ;
28192815
2820- Py_INCREF (res );
2821- return res ;
2816+ Py_INCREF (res );
2817+ return res ;
2818+ }
2819+ generic :
2820+ return PyObject_GenericGetAttr ((PyObject * ) self , nameobj );
28222821}
28232822
28242823static PyTypeObject XMLParser_Type = {
0 commit comments