From 0e438e0ec8f5c3bfbc5d2a9fbd97a6fea973d36b Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Fri, 1 May 2015 00:52:52 +0200 Subject: [PATCH] Improve error checking in get_all() After getting a too big value via ERANGE, making the call with the proper length could still fail due to other issues, and this check is missing. A negative value here would be changed into something weird in the realloc call (which takes size_t), so the error reporting would be bogus. --- xattr.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xattr.c b/xattr.c index 680f6a8..d65601c 100644 --- a/xattr.c +++ b/xattr.c @@ -523,6 +523,13 @@ get_all(PyObject *self, PyObject *args, PyObject *keywds) if(nval == -1) { if(errno == ERANGE) { nval = _get_obj(&tgt, s, NULL, 0); + /* ERANGE + proper size should not fail, but it + still can, so let's check first */ + if(nval == -1) { + res = PyErr_SetFromErrno(PyExc_IOError); + Py_DECREF(mylist); + goto free_buf_val; + } if((buf_val_tmp = PyMem_Realloc(buf_val, nval)) == NULL) { res = PyErr_NoMemory(); Py_DECREF(mylist); -- 2.39.5