From: Dmitry V. L. <ld...@al...> - 2007-09-22 16:25:46
|
Hi, Sorry for long delay, 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. >=20 > I've attached a patch which solves this issue for me, I'd be grateful > for any feedback on it. Essentially I've refactored printstr() and > added a printstrn() function, and I'm now calling this rather than > tprintf() to display the paths. This takes care of escaping > non-printable characters for me. >=20 > Please let me know what you think. 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. 2007-09-22 Dmitry V. Levin <ld...@al...> * net.c (printsock): Output AF_UNIX socket address using printstr() to avoid unprintable characters in output. Suggested by Neil Campbell. --- strace/net.c +++ strace/net.c @@ -937,10 +937,7 @@ =20 =20 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=3Dsizeof(addrbuf); =20 - if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) { + if (addrlen < 2 || addrlen > sizeof(addrbuf)) + addrlen =3D sizeof(addrbuf); + + memset(&addrbuf, 0, sizeof(addrbuf)); + if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) { tprintf("{...}"); return; } + addrbuf.pad[sizeof(addrbuf.pad) - 1] =3D '\0'; =20 tprintf("{sa_family=3D"); printxval(addrfams, addrbuf.sa.sa_family, "AF_???"); @@ -984,12 +984,14 @@ int addrlen; =20 switch (addrbuf.sa.sa_family) { case AF_UNIX: - if (addrlen=3D=3D2) { - tprintf("<nil>"); + if (addrlen =3D=3D 2) { + tprintf("NULL"); } else if (addrbuf.sau.sun_path[0]) { - tprintf("path=3D\"%-.*s\"", addrlen-2, addrbuf.sau.sun_path); + tprintf("path=3D"); + printstr(tcp, addr + 2, strlen(addrbuf.sau.sun_path)); } else { - tprintf("path=3D@%-.*s", addrlen-3, addrbuf.sau.sun_path+1); + tprintf("path=3D@"); + printstr(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1)); } break; case AF_INET: --=20 ldv |