summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Asleson <tasleson@redhat.com>2015-05-04 15:19:48 -0500
committerTony Asleson <tasleson@redhat.com>2015-05-06 08:51:04 -0500
commite8c11c7df0f1d582494922cbadb717296c02e05b (patch)
tree08774f3e8decd209e8d43543ef4504ade5d7a061
parentc21f1ba07a4701b0653bc086673be43ede20efc1 (diff)
downloadlvm2-e8c11c7df0f1d582494922cbadb717296c02e05b.tar.gz
python: Check for NULL value before constructing string property
When retrieving a property value that is a string, if the character pointer in C was NULL, we would segfault. This change checks for non-null before creating a python string representation. In the case where the character pointer is NULL we will return a python 'None' for the value. Signed-off-by: Tony Asleson <tasleson@redhat.com>
-rw-r--r--python/liblvm.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/python/liblvm.c b/python/liblvm.c
index f4a7a2de9..089abb367 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -877,7 +877,11 @@ static PyObject *get_property(struct lvm_property_value *prop)
PyTuple_SET_ITEM(pytuple, 0, Py_BuildValue("K", prop->value.integer));
}
} else {
- PyTuple_SET_ITEM(pytuple, 0, PYSTRTYPE_FROMSTRING(prop->value.string));
+ if ( prop->value.string ) {
+ PyTuple_SET_ITEM(pytuple, 0, PYSTRTYPE_FROMSTRING(prop->value.string));
+ } else {
+ PyTuple_SET_ITEM(pytuple, 0, Py_None);
+ }
}
if (prop->is_settable)