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

Dmitry V. Levin ldv at altlinux.org
Mon Oct 8 21:57:51 UTC 2007


On Wed, Sep 26, 2007 at 03:48:39PM +0100, Neil Campbell wrote:
> Dmitry V. Levin wrot:
> > On Wed, Sep 26, 2007 at 10:28:58AM +0100, Neil Campbell wrote:
> >> 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.
> >> > I propose another patch to avoid unprintable characters in output.
> >>
> >> 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.
> >
> > That is, you suggest to use printpathn() instead?
> 
> I'm not very familiar with the strace source, but this doesn't appear 
> to escape
> the non-printable characters - if such support was added to printpath 
> then yes,
> that would sound good to me.

OK, here is final patch for printsock.

2007-10-01  Dmitry V. Levin <ldv at altlinux.org>

	* net.c (printsock): Output AF_UNIX socket address using
	printpathn() to avoid unprintable characters in output.
	Suggested by Neil Campbell.

--- strace/net.c
+++ strace/net.c
@@ -937,10 +937,7 @@
 
 
 void
-printsock(tcp, addr, addrlen)
-struct tcb *tcp;
-long addr;
-int addrlen;
+printsock(struct tcb *tcp, long addr, int addrlen)
 {
 	union {
 		char pad[128];
@@ -970,13 +967,16 @@ int addrlen;
 		tprintf("%#lx", addr);
 		return;
 	}
-	if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
-		addrlen=sizeof(addrbuf);
 
-	if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
+	if (addrlen < 2 || addrlen > sizeof(addrbuf))
+		addrlen = sizeof(addrbuf);
+
+	memset(&addrbuf, 0, sizeof(addrbuf));
+	if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
 		tprintf("{...}");
 		return;
 	}
+	addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
 
 	tprintf("{sa_family=");
 	printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
@@ -984,12 +984,14 @@ int addrlen;
 
 	switch (addrbuf.sa.sa_family) {
 	case AF_UNIX:
-		if (addrlen==2) {
-			tprintf("<nil>");
+		if (addrlen == 2) {
+			tprintf("NULL");
 		} else if (addrbuf.sau.sun_path[0]) {
-			tprintf("path=\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path);
+			tprintf("path=");
+			printstr(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
 		} else {
-			tprintf("path=@%-.*s", addrlen-3, addrbuf.sau.sun_path+1);
+			tprintf("path=@");
+			printstr(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
 		}
 		break;
 	case AF_INET:

-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20071009/036d7aec/attachment.bin>


More information about the Strace-devel mailing list