From 4fe3ade769b521f3419ddaefb47557b026cac107 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 14 May 2012 22:37:56 +0200 Subject: [PATCH] Fix some potential issues if PyBytes_FromString fails This is unlikely, but if it happens it's ugly. --- xattr.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xattr.c b/xattr.c index c4a5d6c..60b2e9e 100644 --- a/xattr.c +++ b/xattr.c @@ -857,7 +857,13 @@ pylistxattr(PyObject *self, PyObject *args) /* Create and insert the attributes as strings in the list */ for(s = buf, nattrs = 0; s - buf < nret; s += strlen(s) + 1) { - PyList_SET_ITEM(mylist, nattrs, PyBytes_FromString(s)); + PyObject *item = PyBytes_FromString(s); + if(item == NULL) { + Py_DECREF(mylist); + mylist = NULL; + goto freebuf; + } + PyList_SET_ITEM(mylist, nattrs, item); nattrs++; } @@ -955,7 +961,13 @@ xattr_list(PyObject *self, PyObject *args, PyObject *keywds) for(s = buf, nattrs = 0; s - buf < nret; s += strlen(s) + 1) { const char *name = matches_ns(ns, s); if(name!=NULL) { - PyList_SET_ITEM(res, nattrs, PyBytes_FromString(name)); + PyObject *item = PyBytes_FromString(name); + if(item == NULL) { + Py_DECREF(res); + res = NULL; + goto freebuf; + } + PyList_SET_ITEM(res, nattrs, item); nattrs++; } } -- 2.39.5