Skip to content

Commit

Permalink
python3: Handle invalid global config keys
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
stgraber committed Jun 4, 2014
1 parent 3a49134 commit d63b7ba
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/python-lxc/lxc.c
Expand Up @@ -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 *
Expand Down

0 comments on commit d63b7ba

Please sign in to comment.