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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syslog logging handler fails with address in unix abstract namespace #70990
Comments
The traceback: Traceback (most recent call last):
File "Lib/logging/handlers.py", line 917, in emit
self.socket.sendto(msg, self.address)
TypeError: getsockaddrarg: AF_INET address must be tuple, not bytes The attached patch reproduces the issue with a test case and fixes it. |
The following change looks good to me: - if isinstance(address, str):
+ if isinstance(address, (str, bytes)):
self.unixsocket = True
self._connect_unixsocket(address) But I don't understand the testcase. Is an address starting with a NULL character a special address? How does it the bytes address case? + # override the definition in the base class "syslog logging handler fails with address in unix abstract namespace" What is the unix abstract namespace? |
A unix abstract socket address is defined here: "Traditionally, UNIX domain sockets can be either unnamed, or bound to and: "abstract: an abstract socket address is distinguished (from a It is also documented in the Python socket module documentation at |
Ok. And what is the link between abstract namespace and the fact that the syslog handler gets bytes? Is it tested by your change? |
The SysLogHandlerTest class instantiates a 'server_class' that eventually calls the This server_bind() method executes the statements: self.socket.bind(self.server_address)
self.server_address = self.socket.getsockname() and when self.server_address is a string and contains a null byte, then So finally, self.server in SysLogHandlerTest is a bytes object in this case, |
Xavier de Gaye added the comment:
Ah? It sounds strange to me that the type of getsockname() depends on |
makesockaddr() in socketmodule.c calls PyBytes_FromStringAndSize() when the My opinion is not worth much in this matter :). The socket documentation does |
No, it's not possible. Undecode bytes are escaped as surrogate characters using the surrogateescape error handler. See the PEP-393. |
Then it seems that makesockaddr() should be fixed instead of the logging |
Yes. That's why I didn't understand the issue at the beginning :-) Would you like to work on fixing the _socket module? It may be worth to keep your syslog unit test. It's up to you. |
I will give it a try. |
This patch corrects the non-ascii quote character in the Misc/NEWS diff. |
In makesockaddr(), the current implementation does not do any decoding of AF_UNIX addresses in the abstract namespace in the struct sockaddr_un to bytes direction, i.e. system to python direction, but does encode a string or bytes object to struct sockaddr_un in the reverse direction, in getsockaddrarg(). This is not correct. So the patch does more than fixing the type of the addresses as it also fixes this in a non backward compatible way. Maybe this should be indicated in Misc/NEWS. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: