Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Nov 2004 16:54:18 +0100 (CET)
From:      Jilles Tjoelker <jilles@stack.nl>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/74043: [PATCH] sh trap builtin does not properly quote when listing
Message-ID:  <20041117155418.2F2C961D2@hammer.stack.nl>
Resent-Message-ID: <200411171600.iAHG0rbe030928@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         74043
>Category:       bin
>Synopsis:       [PATCH] sh trap builtin does not properly quote when listing
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 17 16:00:53 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Jilles Tjoelker
>Release:        FreeBSD 6.0-CURRENT amd64
>Organization:
MCGV Stack
>Environment:
System: FreeBSD hammer.stack.nl 6.0-CURRENT FreeBSD 6.0-CURRENT #3: Mon Nov 1 18:36:46 CET 2004 marcolz@hammer.stack.nl:/usr/obj/usr/src/sys/HAMMER amd64
>Description:
When listing traps (invoking the trap builtin without arguments), /bin/sh
does not properly quote actions containing single quotes. This should be done
in such a way the output can be input into the shell later, but it is not.
>How-To-Repeat:
jilles@hammer /home/jilles$ /bin/sh
$ trap "echo 'jilles'" USR1 && trap
trap -- 'echo 'jilles'' usr1
$ 
>Fix:
There is already a function to output a string in a way it can be input back
later, so a patch is simple.

--- trap.c.diff begins here ---
--- src/bin/sh/trap.c.orig	Wed Apr  7 10:12:45 2004
+++ src/bin/sh/trap.c	Wed Nov  3 18:16:33 2004
@@ -153,15 +153,14 @@
 	if (argc <= 1) {
 		for (signo = 0 ; signo < sys_nsig ; signo++) {
 			if (signo < NSIG && trap[signo] != NULL) {
+				out1str("trap -- ");
+				out1qstr(trap[signo]);
 				if (signo == 0) {
-					out1fmt("trap -- '%s' %s\n",
-					    trap[signo], "exit");
+					out1str(" exit\n");
 				} else if (sys_signame[signo]) {
-					out1fmt("trap -- '%s' %s\n",
-					    trap[signo], sys_signame[signo]);
+					out1fmt(" %s\n", sys_signame[signo]);
 				} else {
-					out1fmt("trap -- '%s' %d\n",
-					    trap[signo], signo);
+					out1fmt(" %d\n", signo);
 				}
 			}
 		}
--- trap.c.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041117155418.2F2C961D2>