[New-bugs-announce] [issue28815] test_socket fails if /proc/modules is existent but not readable
patrila
report at bugs.python.org
Sun Nov 27 11:16:18 EST 2016
New submission from patrila:
Dear Python developers
The test_socket test fails if /proc/modules is existent but not readable by the user (this is for example the case with the grsecurity patchset of the kernel).
The method reading /proc/modules is isTipcAvailable(), which is not a test but a guard for other tests.
It seems reasonable to return False in the case that /proc/modules is not readable (but existent).
The method isTipcAvailable() already returns False if /proc/modules is non existent (but fails to return False if it's not readable).
Attached a proposed test. Feel free to remove the EISDIR in case you feel uncomfortable and want a it be a "real" error.
The patch should be applied to both Python-2.7 and Python-3.x.
Kind regards
Here is the inline version of the patch; it's also attached.
diff -r 876bee0bd0ba Lib/test/test_socket.py
--- a/Lib/test/test_socket.py Sat Nov 26 14:04:40 2016 -0800
+++ b/Lib/test/test_socket.py Sun Nov 27 17:00:55 2016 +0100
@@ -4779,12 +4779,21 @@
"""
if not hasattr(socket, "AF_TIPC"):
return False
- if not os.path.isfile("/proc/modules"):
- return False
- with open("/proc/modules") as f:
- for line in f:
- if line.startswith("tipc "):
- return True
+ try:
+ f = open("/proc/modules")
+ except IOError as e:
+ # It's ok if the file does not exist, is a directory or if we
+ # have not the permission to read it. In any other case it's a
+ # real error, so raise it again.
+ if e.errno in (ENOENT, EISDIR, EACCES):
+ return False
+ else:
+ raise
+ else:
+ with f:
+ for line in f:
+ if line.startswith("tipc "):
+ return True
return False
@unittest.skipUnless(isTipcAvailable(),
----------
files: test_socket_isTipcAvailable_proc_modules.patch
keywords: patch
messages: 281828
nosy: patrila
priority: normal
severity: normal
status: open
title: test_socket fails if /proc/modules is existent but not readable
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45666/test_socket_isTipcAvailable_proc_modules.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28815>
_______________________________________
More information about the New-bugs-announce
mailing list