Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-100218: correctly seterrno whensocket.if_{nametoindex,indextoname} raiseOSError#140905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletionsLib/test/test_socket.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1176,7 +1176,10 @@ def testInterfaceNameIndex(self):
'socket.if_indextoname() not available.')
@support.skip_android_selinux('if_indextoname')
def testInvalidInterfaceIndexToName(self):
self.assertRaises(OSError, socket.if_indextoname, 0)
with self.assertRaises(OSError) as cm:
socket.if_indextoname(0)
self.assertIsNotNone(cm.exception.errno)

self.assertRaises(ValueError, socket.if_indextoname, -1)
self.assertRaises(OverflowError, socket.if_indextoname, 2**1000)
self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF')
Expand All@@ -1196,8 +1199,11 @@ def testInvalidInterfaceIndexToName(self):
'socket.if_nametoindex() not available.')
@support.skip_android_selinux('if_nametoindex')
def testInvalidInterfaceNameToIndex(self):
with self.assertRaises(OSError) as cm:
socket.if_nametoindex("_DEADBEEF")
self.assertIsNotNone(cm.exception.errno)

self.assertRaises(TypeError, socket.if_nametoindex, 0)
self.assertRaises(OSError, socket.if_nametoindex, '_DEADBEEF')

@unittest.skipUnless(hasattr(sys, 'getrefcount'),
'test needs sys.getrefcount()')
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Correctly set :attr:`~OSError.errno` when :func:`socket.if_nametoindex` or
:func:`socket.if_indextoname` raise an :exc:`OSError`. Patch by Bénédikt
Tran.
5 changes: 3 additions & 2 deletionsModules/socketmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7294,10 +7294,10 @@ _socket_if_nametoindex_impl(PyObject *module, PyObject *oname)
unsigned long index;
#endif

errno = ENODEV; // in case 'if_nametoindex' does not set errno
index = if_nametoindex(PyBytes_AS_STRING(oname));
if (index == 0) {
/* if_nametoindex() doesn't set errno */
PyErr_SetString(PyExc_OSError, "no interface with this name");
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

Expand All@@ -7317,6 +7317,7 @@ static PyObject *
_socket_if_indextoname_impl(PyObject *module, NET_IFINDEX index)
/*[clinic end generated code: output=e48bc324993052e0 input=c93f753d0cf6d7d1]*/
{
errno = ENXIO; // in case 'if_indextoname' does not set errno
char name[IF_NAMESIZE + 1];
if (if_indextoname(index, name) == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp