[lxc-devel] [PATCH 2/2] python3: Handle invalid global config keys

Stéphane Graber stgraber at ubuntu.com
Tue Jun 3 13:59:06 UTC 2014


Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 src/python-lxc/lxc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index d436c28..a8ab65b 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -329,12 +329,20 @@ LXC_get_global_config_item(PyObject *self, PyObject *args, PyObject *kwds)
 {
     static char *kwlist[] = {"key", NULL};
     char* key = NULL;
+    const char* value = NULL;
 
     if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist,
                                       &key))
         return NULL;
 
-    return PyUnicode_FromString(lxc_get_global_config_item(key));
+    value = lxc_get_global_config_item(key);
+
+    if (!value) {
+        PyErr_SetString(PyExc_KeyError, "Invalid configuration key");
+        return NULL;
+    }
+
+    return PyUnicode_FromString(value);
 }
 
 static PyObject *
-- 
1.9.1



More information about the lxc-devel mailing list