From 5be22f1aa8c5adce7f0b66d9668986f35381a688 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Tue, 24 Jun 2014 23:23:12 +0200 Subject: [PATCH] First step towards fixing qualifier overflow This is still a work-in-progress, since it only deals with Python-level overflows, but it's a step forward. --- acl.c | 6 +++++- test/test_acls.py | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/acl.c b/acl.c index 8d757ab..22f83fe 100644 --- a/acl.c +++ b/acl.c @@ -841,7 +841,11 @@ static int Entry_set_qualifier(PyObject* obj, PyObject* value, void* arg) { "qualifier must be integer"); return -1; } - uidgid = PyInt_AsLong(value); + if((uidgid = PyInt_AsLong(value)) == -1) { + if(PyErr_Occurred() != NULL) { + return -1; + } + } if(acl_set_qualifier(self->entry, (void*)&uidgid) == -1) { PyErr_SetFromErrno(PyExc_IOError); return -1; diff --git a/test/test_acls.py b/test/test_acls.py index 08bfd4e..eea3f36 100644 --- a/test/test_acls.py +++ b/test/test_acls.py @@ -3,7 +3,7 @@ """Unittests for the posix1e module""" -# Copyright (C) 2002-2009, 2012 Iustin Pop +# Copyright (C) 2002-2009, 2012, 2014 Iustin Pop # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -40,6 +40,9 @@ M0500 = 320 # octal 0500 M0644 = 420 # octal 0644 M0755 = 493 # octal 755 +# Check if running under Python 3 +IS_PY_3K = sys.hexversion >= 0x03000000 + def _skip_test(fn): """Wrapper to skip a test""" new_fn = lambda x: None @@ -320,5 +323,18 @@ class ModificationTests(aclTest, unittest.TestCase): " after deletion" % pmap[perm]) + @has_ext(HAS_ACL_ENTRY and IS_PY_3K) + def testQualifierOverflow(self): + """Tests qualifier overflow handling""" + acl = posix1e.ACL() + e = acl.append() + qualifier = sys.maxsize * 2 + for tag in [posix1e.ACL_USER, posix1e.ACL_GROUP]: + e.tag_type = posix1e.ACL_USER + with self.assertRaises(OverflowError): + e.qualifier = qualifier + print(e.qualifier) + + if __name__ == "__main__": unittest.main() -- 2.39.2