Subject: bin/35283: kdump doesn't escape newlines in argv
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <dholland@eecs.harvard.edu>
List: netbsd-bugs
Date: 12/19/2006 21:20:01
>Number:         35283
>Category:       bin
>Synopsis:       kdump doesn't escape newlines in argv
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 19 21:20:01 +0000 2006
>Originator:     David A. Holland / dholland@eecs.harvard.edu
>Release:        NetBSD 4.99.3 (-20061010)
>Organization:
    Harvard EECS
>Environment:
System: NetBSD tanaqui 4.99.3 NetBSD 4.99.3 (TANAQUI) #6: Tue Oct 10 19:32:37 EDT 2006 dholland@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386
>Description:

If you have newlines in an argv string, kdump doesn't escape them,
which renders the output non-machine-parseable.

>How-To-Repeat:

I hit it with this:

	% cd /usr/pkgsrc/lang/gawk
	% ktrace -d -i -tacnv "$@"
	% kdump -n | [some scripts]

With today's pkgsrc (20061219), at line 521,808 in the output one gets

 10107 sh       ARG   "
	      N
	      s,$,-,
	      : loop
	      s,^\\([0123456789]*\\)\\(.*\\)[$]LINENO\\([^abcdefghijklmnopqrst\
	uvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]\\),\\1\\2\\1\\3,
	      t loop
	      s,-$,,
	      s,^[0123456789]*\\n,,
	    "

which ought to be

 10107 sh       ARG   "\n      N\n      s,$,-,\n      : loop\n      s,^\\([012\
        3456789]*\\)\\(.*\\)[$]LINENO\\([^abcdefghijklmnopqrstuvwxyzABCDEFGHIJ\
        KLMNOPQRSTUVWXYZ0123456789_]\\),\\1\\2\\1\\3,\n      t loop\n      s,-\
        $,,\n      s,^[0123456789]*\\n,,\n    "


It wouldn't be too hard to come up with an easier example if one were
wanted.

>Fix:

This patch is actually against (and tested on) 3.1_STABLE of 20061215,
but it'll apply to -current as nothing in the vicinity seems to have
changed since then.

Index: kdump.c
===================================================================
RCS file: /cvsroot/src/usr.bin/kdump/kdump.c,v
retrieving revision 1.79
diff -u -r1.79 kdump.c
--- kdump.c	23 Aug 2004 20:49:28 -0000	1.79
+++ kdump.c	19 Dec 2006 21:08:01 -0000
@@ -738,7 +738,7 @@
 	col++;
 	for (; datalen > 0; datalen--, dp++) {
 		(void)svis(visbuf, *dp, VIS_CSTYLE,
-		    datalen > 1 ? *(dp + 1) : 0, "\"");
+		    datalen > 1 ? *(dp + 1) : 0, "\"\n");
 		cp = visbuf;
 		/*
 		 * Keep track of printables and