From c58e742b603eeaa4c3b07e04d72a65becb82c636 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Tue, 15 May 2012 00:17:39 +0200 Subject: [PATCH] Check merge_ns return value in all places This eliminates another potential round of errors. Also add cpychecker attribute for even less noise. --- xattr.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/xattr.c b/xattr.c index ba3fb82..dc8ad00 100644 --- a/xattr.c +++ b/xattr.c @@ -76,6 +76,11 @@ __attribute__((cpychecker_negative_result_sets_exception)) static int convertObj(PyObject *myobj, target_t *tgt, int nofollow) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; +static int merge_ns(const char *ns, const char *name, + const char **result, char **buf) + CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; + + /** Converts from a string, file or int argument to what we need. * * Returns -1 on failure, 0 on success. @@ -311,7 +316,10 @@ xattr_get(PyObject *self, PyObject *args, PyObject *keywds) goto freearg; } - merge_ns(ns, attrname, &fullname, &namebuf); + if(merge_ns(ns, attrname, &fullname, &namebuf) < 0) { + res = NULL; + goto freearg; + } /* Find out the needed size of the buffer */ if((nalloc = _get_obj(&tgt, fullname, NULL, 0)) == -1) { @@ -651,13 +659,15 @@ xattr_set(PyObject *self, PyObject *args, PyObject *keywds) goto freearg; } - merge_ns(ns, attrname, &full_name, &newname); + if(merge_ns(ns, attrname, &full_name, &newname) < 0) { + res = NULL; + goto freearg; + } /* Set the attribute's value */ nret = _set_obj(&tgt, full_name, buf, bufsize, flags); - if(newname != NULL) - PyMem_Free(newname); + PyMem_Free(newname); free_tgt(&tgt); -- 2.39.5