diff options
author | Prashanth Pai <ppai@redhat.com> | 2016-05-30 15:08:48 +0530 |
---|---|---|
committer | Prashanth Pai <ppai@redhat.com> | 2016-06-15 15:02:18 +0530 |
commit | b111d50347076336b3e655178d967f8e5c8c9913 (patch) | |
tree | b4ad1944d0379f560fae379efd27d69e7c12eb65 /test/functional/libgfapi-python-tests.py | |
parent | 759471ddcd76306b952bb2ee28f211afc9e24f3a (diff) |
Add validation decorators
As glfs and glfd are pointers to memory locations, passing invalid
values of glfs and glfd to the libgfapi C library can result in
segfault. This patch introduces decorators that validate glfs
and glfd before calling correspoding C APIs.
Change-Id: I4e86bd8e436e23cd41f75f428d246939c820bb9c
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/functional/libgfapi-python-tests.py')
-rw-r--r-- | test/functional/libgfapi-python-tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py index c29f400..4e339e0 100644 --- a/test/functional/libgfapi-python-tests.py +++ b/test/functional/libgfapi-python-tests.py @@ -127,6 +127,29 @@ class FileOpsTest(unittest.TestCase): self.assertRaises(OSError, self.vol.open, "file", 12345) + def test_double_close(self): + name = uuid4().hex + f = self.vol.fopen(name, 'w') + f.close() + for i in range(2): + try: + f.close() + except OSError as err: + self.assertEqual(err.errno, errno.EBADF) + else: + self.fail("Expecting OSError") + + def test_glfd_decorators_IO_on_invalid_glfd(self): + name = uuid4().hex + with self.vol.fopen(name, 'w') as f: + f.write("Valar Morghulis") + try: + s = f.read() + except OSError as err: + self.assertEqual(err.errno, errno.EBADF) + else: + self.fail("Expecting OSError") + def test_fopen_err(self): # mode not string self.assertRaises(TypeError, self.vol.fopen, "file", os.O_WRONLY) |