mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-11-04 01:37:31 +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>
 | 
			
		||||
 | 
			
		||||
	* 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
 | 
			
		||||
	the internal status.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -136,11 +136,14 @@ binary_quote(binaryObject *self)
 | 
			
		|||
    const char *buffer;
 | 
			
		||||
    int buffer_len;
 | 
			
		||||
    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 (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
 | 
			
		||||
    else if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
 | 
			
		||||
        /* escape and build quoted buffer */
 | 
			
		||||
        PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
 | 
			
		||||
 | 
			
		||||
        to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len,
 | 
			
		||||
            self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
 | 
			
		||||
        if (to == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,6 +63,9 @@ class TypesBasicTests(TestCase):
 | 
			
		|||
	r = str(self.execute("SELECT %s::bytea AS foo", (b,)))
 | 
			
		||||
        self.failUnless(r == s, "wrong binary quoting")
 | 
			
		||||
 | 
			
		||||
        b = psycopg2.Binary('')
 | 
			
		||||
        self.assertEqual(str(b), '')
 | 
			
		||||
 | 
			
		||||
    def testArray(self):
 | 
			
		||||
	s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))
 | 
			
		||||
	self.failUnless(s == [[1,2],[3,4]], "wrong array quoting " + str(s))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user