mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Empty binary buffer segfault fix (closes: #119).
This commit is contained in:
parent
8eb118c63f
commit
f88b973bd1
|
@ -1,5 +1,8 @@
|
||||||
2006-09-01 Federico Di Gregorio <fog@initd.org>
|
2006-09-01 Federico Di Gregorio <fog@initd.org>
|
||||||
|
|
||||||
|
* psycopg/adapter_binary.c: applied patch from jdahlin (#119)
|
||||||
|
to fix the segfault on empty binary buffers.
|
||||||
|
|
||||||
* psycopg/connection_type.c: added .status attribute to expose
|
* psycopg/connection_type.c: added .status attribute to expose
|
||||||
the internal status.
|
the internal status.
|
||||||
|
|
||||||
|
|
|
@ -137,10 +137,13 @@ binary_quote(binaryObject *self)
|
||||||
int buffer_len;
|
int buffer_len;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
|
if (self->buffer == NULL)
|
||||||
|
self->buffer = PyString_FromString("");
|
||||||
/* if we got a plain string or a buffer we escape it and save the buffer */
|
/* if we got a plain string or a buffer we escape it and save the buffer */
|
||||||
if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
|
else if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
|
||||||
/* escape and build quoted buffer */
|
/* escape and build quoted buffer */
|
||||||
PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
|
PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
|
||||||
|
|
||||||
to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len,
|
to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len,
|
||||||
self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
|
self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
|
||||||
if (to == NULL) {
|
if (to == NULL) {
|
||||||
|
|
|
@ -63,6 +63,9 @@ class TypesBasicTests(TestCase):
|
||||||
r = str(self.execute("SELECT %s::bytea AS foo", (b,)))
|
r = str(self.execute("SELECT %s::bytea AS foo", (b,)))
|
||||||
self.failUnless(r == s, "wrong binary quoting")
|
self.failUnless(r == s, "wrong binary quoting")
|
||||||
|
|
||||||
|
b = psycopg2.Binary('')
|
||||||
|
self.assertEqual(str(b), '')
|
||||||
|
|
||||||
def testArray(self):
|
def testArray(self):
|
||||||
s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))
|
s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))
|
||||||
self.failUnless(s == [[1,2],[3,4]], "wrong array quoting " + str(s))
|
self.failUnless(s == [[1,2],[3,4]], "wrong array quoting " + str(s))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user