[lxc-devel] [PATCH 2/2] python3: Handle invalid global config keys
Serge Hallyn
serge.hallyn at ubuntu.com
Tue Jun 3 15:29:25 UTC 2014
Quoting Stéphane Graber (stgraber at ubuntu.com):
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn 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
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
More information about the lxc-devel
mailing list