[lvm-devel] [PATCH 3/5] python: Check for NULL value before constructing string property
Tony Asleson
tasleson at redhat.com
Tue May 5 21:34:17 UTC 2015
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 at redhat.com>
---
python/liblvm.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index f4a7a2d..089abb3 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)
--
1.8.2.1
More information about the lvm-devel
mailing list