mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-10 04:10:19 +00:00
Fix for CONPY-175:
Since memory for stack allocation is limited, we need to allocate memory from the heap, otherwise in case of large strings escape_string method might crash.
This commit is contained in:
@ -681,9 +681,13 @@ static PyObject *MrdbConnection_escape_string(MrdbConnection *self,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
from= (char *)PyUnicode_AsUTF8AndSize(string, (Py_ssize_t *)&from_length);
|
from= (char *)PyUnicode_AsUTF8AndSize(string, (Py_ssize_t *)&from_length);
|
||||||
to= (char *)alloca(from_length * 2 + 1);
|
if (!(to= (char *)PyMem_RawCalloc(1, from_length * 2 + 1)))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
to_length= mysql_real_escape_string(self->mysql, to, from, (unsigned long)from_length);
|
to_length= mysql_real_escape_string(self->mysql, to, from, (unsigned long)from_length);
|
||||||
new_string= PyUnicode_FromStringAndSize(to, to_length);
|
new_string= PyUnicode_FromStringAndSize(to, to_length);
|
||||||
|
PyMem_Free(to);
|
||||||
return new_string;
|
return new_string;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -219,5 +219,14 @@ class TestConnection(unittest.TestCase):
|
|||||||
con.autocommit= False
|
con.autocommit= False
|
||||||
self.assertTrue(not con.server_status & STATUS.AUTOCOMMIT)
|
self.assertTrue(not con.server_status & STATUS.AUTOCOMMIT)
|
||||||
|
|
||||||
|
def test_conpy175(self):
|
||||||
|
default_conf= conf()
|
||||||
|
c1 = mariadb.connect(**default_conf)
|
||||||
|
str= '"' * 4194304
|
||||||
|
newstr= c1.escape_string(str);
|
||||||
|
self.assertEqual(newstr, '\\"' * 4194304)
|
||||||
|
c1.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user