← Commit list

496d5bf4c

Denys Vlasenko
Denys Vlasenko
2010-03-26
FAILED Duration: 29s

Subject

ash: trap with bad signal name should not abort

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/ash.c+10 -4
@@ -12281,7 +12281,7 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
char *action;
char **ap;
- int signo;
+ int signo, exitcode;
nextopt(nullstr);
ap = argptr;
@@ -12314,10 +12314,15 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
action = NULL;
if (ap[1])
action = *ap++;
+ exitcode = 0;
while (*ap) {
signo = get_signum(*ap);
- if (signo < 0)
- ash_msg_and_raise_error("%s: bad trap", *ap);
+ if (signo < 0) {
+ /* Mimic bash message exactly */
+ ash_msg("%s: invalid signal specification", *ap);
+ exitcode = 1;
+ goto next;
+ }
INT_OFF;
if (action) {
if (LONE_DASH(action))
@@ -12330,9 +12335,10 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
if (signo != 0)
setsignal(signo);
INT_ON;
+ next:
ap++;
}
- return 0;
+ return exitcode;
}
shell/ash_test/ash-signals/signal4.right+4 -0
@@ -0,0 +1,4 @@
+./signal4.tests: trap: line 3: BADNAME: invalid signal specification
+1
+Trapped
+Ok
shell/ash_test/ash-signals/signal4.tests+5 -0
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+trap "echo Trapped" BADNAME TERM; echo $?
+kill $$
+echo Ok