From b111d50347076336b3e655178d967f8e5c8c9913 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Mon, 30 May 2016 15:08:48 +0530 Subject: 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 --- test/functional/libgfapi-python-tests.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/functional/libgfapi-python-tests.py') 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) -- cgit