From: Dmitry V. L. <ld...@al...> - 2007-10-08 21:58:54
|
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 seem= ed > >> >> that this was due to some strange paths being included in unix doma= in > >> >> 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? >=20 > I'm not very familiar with the strace source, but this doesn't appear=20 > to escape > the non-printable characters - if such support was added to printpath=20 > then yes, > that would sound good to me. OK, here is final patch for printsock. 2007-10-01 Dmitry V. Levin <ld...@al...> * 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 @@ =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 |