[PATCH] net.c (printsock): Output AF_UNIX socket address using printstr

Neil Campbell lists at thebatcave.org.uk
Wed Sep 26 09:28:58 UTC 2007


Dmitry V. Levin wrote:
> On Sat, Aug 25, 2007 at 01:21:00PM +0100, Neil Campbell wrote:
>> I was tracing some applications and found that the output of strace
>> included some non-printable characters, leading various tools such as
>> 'file' and 'less' to refuse to recognise the file as text.  It seemed
>> that this was due to some strange paths being included in unix domain
>> sockaddr structs.
> 
> While your suggestion to avoid unprintable characters in output is right,
> your patch looks too intrusive: printstr() seems to be enough, and
> strnlen() is a GNU extension.
> 
> I propose another patch to avoid unprintable characters in output.

Hi Dmitry,

Thanks for your reply.  I agree that the patch you posted is much
cleaner than mine, however, I think that there is one small problem with
it.  By simply calling printstr, the path in the sockaddr struct will
get truncated as if it were data (like the data shown for read syscalls)
according to the size of the '-s' argument, ie 32 by default.

In most cases however this path will be a genuine path to a file, and
the current code in CVS will print this in full, which is consistent
with how paths are handled elsewhere.

For example, in the current CVS version (and with my original change) I
can see something like this:

connect(3, {sa_family=AF_FILE,
path="/tmp/a_rather_long_path_name_like_this_which_has_plenty_of_chars/some_file"},
110) = -1 ENOENT (No such file or directory)

Applying your patch, this changes to:

connect(3, {sa_family=AF_FILE,
path="/tmp/a_rather_long_path_name_lik"...}, 110) = -1 ENOENT (No such
file or directory)

With this in mind, perhaps what we really want is a function to print
paths that goes through the printstr code, or something similar.  My
original patch was a little short-sighted, as I can see now that passing
a path with non-printable characters to any other syscall, such as
open() will also fail to escape the characters correctly.  If we add
such a function it can be used by printsock as well as by other
functions that require paths.

How does this sound?  If you think that would be a useful thing to do, I
can get to work on a patch.

Thanks,
Neil




More information about the Strace-devel mailing list