[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-21 Thread Xavier de Gaye

Xavier de Gaye added the comment:

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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

This patch corrects the non-ascii quote character in the Misc/NEWS diff.

--
Added file: http://bugs.python.org/file42543/unix_abstract_namespace_3.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

Here is the patch.

As a  reference, issue #8373 with changeset 1f23bb74f4bc changed the AF_UNIX
socket addresses encoding from UTF-8 to the file system encoding and the
'surrogateescape' error handler (PEP 383).

--
Added file: http://bugs.python.org/file42542/unix_abstract_namespace_2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

I will give it a try.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread STINNER Victor

STINNER Victor added the comment:

> Then it seems that makesockaddr() should be fixed instead of the logging 
> handler.

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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

Then it seems that makesockaddr() should be fixed instead of the logging
handler.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

makesockaddr() in socketmodule.c calls PyBytes_FromStringAndSize() when the
first byte is a null byte.

My opinion is not worth much in this matter :). The socket documentation does
say that AF_UNIX addresses are "represented as a string, using the file system
encoding", so the implementation looks wrong. However it is possible that
PyUnicode_DecodeFSDefault() fails for some file system encodings when the
encoded address contains null bytes ?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread STINNER Victor

STINNER Victor added the comment:

> However it is possible that
PyUnicode_DecodeFSDefault() fails for some file system encodings when the
encoded address contains null bytes ?

No, it's not possible. Undecode bytes are escaped as surrogate characters using 
the surrogateescape error handler. See the PEP 393.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread STINNER Victor

STINNER Victor added the comment:

Xavier de Gaye added the comment:
> when self.server_address is a string and contains a null byte, then
> getsockname() returns a bytes object.

Ah? It sounds strange to me that the type of getsockname() depends on
the NULL byte. I would also expect a Unicode name for the abstract
namespace. What do you think?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

The SysLogHandlerTest class instantiates a 'server_class' that eventually calls 
the
server_bind() method of the TCPServer class of the socketserver module.

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
getsockname() returns a bytes object.

So finally, self.server in SysLogHandlerTest is a bytes object in this case,
hence the needed to fix Lib/logging/handlers.py.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread STINNER Victor

STINNER Victor added the comment:

Ok. And what is the link between abstract namespace and the fact that the 
syslog handler gets bytes? Is it tested by your change?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com




[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-20 Thread Xavier de Gaye

Xavier de Gaye added the comment:

A unix abstract socket address is defined here:
http://man7.org/linux/man-pages/man7/unix.7.html
as:

"Traditionally, UNIX domain sockets can be either unnamed, or bound to
a filesystem pathname (marked as being of type socket).  Linux also
supports an abstract namespace which is independent of the
filesystem."

and:

"abstract: an abstract socket address is distinguished (from a
pathname socket) by the fact that sun_path[0] is a null byte ('\0').
..."

It is also documented in the Python socket module documentation at
https://docs.python.org/3/library/socket.html
and tested in the TestLinuxAbstractNamespace test of
Lib/test/test_socket.py.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-19 Thread STINNER Victor

STINNER Victor added the comment:

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
+self.address = '\x00python_logging_test'

"syslog logging handler fails with address in unix abstract namespace"

What is the unix abstract namespace?

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26803] syslog logging handler fails with address in unix abstract namespace

2016-04-19 Thread Xavier de Gaye

New submission from Xavier de Gaye:

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.

--
components: Library (Lib)
files: unix_abstract_namespace.patch
keywords: patch
messages: 263715
nosy: vinay.sajip, xdegaye
priority: normal
severity: normal
status: open
title: syslog logging handler fails with address in unix abstract namespace
type: behavior
versions: Python 3.6
Added file: http://bugs.python.org/file42513/unix_abstract_namespace.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com