Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a9017c39
Commit
a9017c39
authored
Apr 19, 2006
by
Armin Rigo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF Patch #1062014: AF_UNIX sockets under Linux have a special
abstract namespace that is now fully supported.
parent
ab012af6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
6 deletions
+62
-6
Lib/test/test_socket.py
Lib/test/test_socket.py
+28
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/socketmodule.c
Modules/socketmodule.c
+31
-6
No files found.
Lib/test/test_socket.py
View file @
a9017c39
...
...
@@ -825,6 +825,32 @@ class TestExceptions(unittest.TestCase):
self
.
assert_
(
issubclass
(
socket
.
gaierror
,
socket
.
error
))
self
.
assert_
(
issubclass
(
socket
.
timeout
,
socket
.
error
))
class
TestLinuxAbstractNamespace
(
unittest
.
TestCase
):
UNIX_PATH_MAX
=
108
def
testLinuxAbstractNamespace
(
self
):
address
=
"
\
x00
python-test-hello
\
x00
\
xff
"
s1
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
s1
.
bind
(
address
)
s1
.
listen
(
1
)
s2
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
s2
.
connect
(
s1
.
getsockname
())
s1
.
accept
()
self
.
assertEqual
(
s1
.
getsockname
(),
address
)
self
.
assertEqual
(
s2
.
getpeername
(),
address
)
def
testMaxName
(
self
):
address
=
"
\
x00
"
+
"h"
*
(
self
.
UNIX_PATH_MAX
-
1
)
s
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
s
.
bind
(
address
)
self
.
assertEqual
(
s
.
getsockname
(),
address
)
def
testNameOverflow
(
self
):
address
=
"
\
x00
"
+
"h"
*
self
.
UNIX_PATH_MAX
s
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
self
.
assertRaises
(
socket
.
error
,
s
.
bind
,
address
)
def
test_main
():
tests
=
[
GeneralModuleTests
,
BasicTCPTest
,
TCPTimeoutTest
,
TestExceptions
]
...
...
@@ -840,6 +866,8 @@ def test_main():
])
if
hasattr
(
socket
,
"socketpair"
):
tests
.
append
(
BasicSocketPairTest
)
if
sys
.
platform
==
'linux2'
:
tests
.
append
(
TestLinuxAbstractNamespace
)
test_support
.
run_unittest
(
*
tests
)
if
__name__
==
"__main__"
:
...
...
Misc/NEWS
View file @
a9017c39
...
...
@@ -80,6 +80,9 @@ Extension Modules
- Bug #1332852: bsddb module minimum BerkeleyDB version raised to 3.3
as older versions cause excessive test failures.
- Patch #1062014: AF_UNIX sockets under Linux have a special
abstract namespace that is now fully supported.
Library
-------
...
...
Modules/socketmodule.c
View file @
a9017c39
...
...
@@ -968,7 +968,18 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
case
AF_UNIX
:
{
struct
sockaddr_un
*
a
=
(
struct
sockaddr_un
*
)
addr
;
return
PyString_FromString
(
a
->
sun_path
);
#ifdef linux
if
(
a
->
sun_path
[
0
]
==
0
)
{
/* Linux abstract namespace */
addrlen
-=
(
sizeof
(
*
a
)
-
sizeof
(
a
->
sun_path
));
return
PyString_FromStringAndSize
(
a
->
sun_path
,
addrlen
);
}
else
#endif
/* linux */
{
/* regular NULL-terminated string */
return
PyString_FromString
(
a
->
sun_path
);
}
}
#endif
/* AF_UNIX */
...
...
@@ -1098,14 +1109,28 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
addr
=
(
struct
sockaddr_un
*
)
&
(
s
->
sock_addr
).
un
;
if
(
!
PyArg_Parse
(
args
,
"t#"
,
&
path
,
&
len
))
return
0
;
if
(
len
>=
sizeof
addr
->
sun_path
)
{
PyErr_SetString
(
socket_error
,
"AF_UNIX path too long"
);
return
0
;
#ifdef linux
if
(
len
>
0
&&
path
[
0
]
==
0
)
{
/* Linux abstract namespace extension */
if
(
len
>
sizeof
addr
->
sun_path
)
{
PyErr_SetString
(
socket_error
,
"AF_UNIX path too long"
);
return
0
;
}
}
else
#endif
/* linux */
{
/* regular NULL-terminated string */
if
(
len
>=
sizeof
addr
->
sun_path
)
{
PyErr_SetString
(
socket_error
,
"AF_UNIX path too long"
);
return
0
;
}
addr
->
sun_path
[
len
]
=
0
;
}
addr
->
sun_family
=
s
->
sock_family
;
memcpy
(
addr
->
sun_path
,
path
,
len
);
addr
->
sun_path
[
len
]
=
0
;
*
addr_ret
=
(
struct
sockaddr
*
)
addr
;
#if defined(PYOS_OS2)
*
len_ret
=
sizeof
(
*
addr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment