missing type check in pyitem.sip

abel deuring <[email protected]> Fri, 07 Jan 2005 16:32:18 +0100
Newsgroups gmane.comp.db.rekall.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------090403000404000203070107
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

[Rekall 2.2.3 on Debian/testing]

Hi,

a call of the Python method setValue of a form field with a value of the 
"wrong" type can lead to "deferred error", like

	field.setValue(0, None)

The function sipDo_PyKBItem_setValue in sipRekallPyKBItem.cpp/pyitem.sip 
misses a type check:

if      (PyInt_Check     (pyValue))
	pyItem->setValue (row, KBValue((int)PyInt_AsLong  (pyValue))) ;
else if (PyLong_Check    (pyValue))
	pyItem->setValue (row, KBValue((int)PyLong_AsLong (pyValue))) ;
else if (PyFloat_Check   (pyValue))
pyItem->setValue (row, KBValue(PyFloat_AsDouble   (pyValue))) ;
else
	pyItem->setValue (row, PyString_AsString(pyValue), 
PyString_Size(pyValue)) ;

If pyValue points to a non-string/unicode/Int/Long/Float object, 
PyString_AsString raises a TypeError. Since this exception is not caught 
here, it will show up at some later time for a completely innocent 
statement, and can hence be a bit diffult to trace down ;)

A quick patch for pyitem.sip is attached.

BTW, the None value as in the example above came in my case from a call 
to the getValue method of another field that has the attribute "empty is 
null" set. I think a proper fix should also allow to _set_ the None/null 
value for such fields.

Abel

--------------090403000404000203070107
Content-Type: text/plain;
 name="pyitem.sip.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="pyitem.sip.diff"

--- rekall-2.2.3-orig/script/python/lib/pyitem.sip	2004-11-18 19:26:23.000000000 +0100
+++ rekall-2.2.3/script/python/lib/pyitem.sip	2005-01-07 16:10:30.000000000 +0100
@@ -31,7 +31,11 @@
 		else if (PyFloat_Check   (pyValue))
 			pyItem->setValue (row, KBValue(PyFloat_AsDouble   (pyValue))) ;
 		else
-			pyItem->setValue (row, PyString_AsString(pyValue), PyString_Size(pyValue)) ;
+		{
+			char *s = PyString_AsString(pyValue);
+			if (!s) return 0;
+			pyItem->setValue (row, s, PyString_Size(pyValue)) ;
+		}
 
 		return	Py_None	;
 	}

--------------090403000404000203070107
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Rekall-devel mailing list
[email protected]
http://www.mailman.a-i-s.co.uk/cgi-bin/mailman/listinfo/rekall-devel
--------------090403000404000203070107--