🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.debian.bugs.dist
1 messages
1 total messages Started by andrew bezella Tue, 10 Nov 2026 23:40
Bug#1153685: sash -c exits 0 for failing commands containing shell metacharacters
#4083
Author: andrew bezella
Date: Tue, 10 Nov 2026 23:40
125 lines
5775 bytes
This is a multi-part MIME message sent by reportbug.


--===============8884418094617090387==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Package: sash
Version: 3.8-7+b13
Severity: normal
Tags: patch upstream
X-Debbugs-Cc: abezella@archive.org

Dear Maintainer,

Thank you for your time and effort in supporting Debian.

I noticed this when backupninja failures were not reported as such. I
used AI to help diagnose it and write the patch. I have read the patch,
confirmed the diagnosis against the source, and tested the rebuilt package
as shown below but I am not a C developer.  Please review it with that
in mind.

When a command line contains characters other than letters, digits, blanks
and . / - + = _ : , ' ", sash runs it through system(). The exit status is
then lost, so failures are reported as success.

Steps to reproduce, with expected results from the attached patch:

  command                          3.8-7   patched
  sash -c 'false'                    1        1
  sash -c 'false @'                  0        1
  sash -c "sh -c 'exit 3' @"         0        3
  sash -c 'kill -9 $$'               9      137

Cause:

runCmd() returns trySystem(cmd) for commands with metacharacters.
trySystem() in utils.c returns the raw wait status from system(), despite
its comment saying it returns the command's exit status. main() returns
that value, so exit code n becomes n << 8, which the 8-bit exit status
truncates to 0. Only signal deaths survive, as the bare signal number.
The makeArgs() fallback in childProcess() has the same problem.

This is an incomplete implementation of #281728 ("use the exit status of
the last command as our exit status"), which upstream 3.8 adopted ("The
exit status for commands has been implemented"). The shell path was
converted with system()'s raw return value instead of the decoded exit
status.

Fix:

The attached patch decodes the status in trySystem() with WEXITSTATUS(),
and returns 128 + WTERMSIG() for signals. Callers' -1 checks are
unaffected.

Tested by rebuilding 3.8-7 with the patch on trixie. It gives the results
in the "patched" column.

Separately, the fork/exec path in runCmd() returns -1 for a signalled
child, so sash exits 255 instead of 128 + signal.


-- System Information:
Debian Release: 13.7
  APT prefers stable-updates
  APT policy: (990, 'stable-updates'), (990, 'stable-security'), (990, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.12.115+deb13.1-amd64 (SMP w/14 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US.UTF-8:en.UTF-8
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- no debconf information

--===============8884418094617090387==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="fix_trysystem_exit_status.patch"

Description: Return decoded exit status from trySystem()
 trySystem() returned the raw wait status from system() instead of the
 exit code. Commands containing shell metacharacters are run through
 trySystem(), so a failing command made "sash -c" exit 0: an exit code
 of n became n << 8, which the 8-bit exit status truncates to 0.
 .
 Decode the status with WEXITSTATUS(), and return 128 + signal for a
 command killed by a signal. Callers' checks for -1 are unaffected.
Forwarded: no
Last-Update: 2026-11-10

--- a/utils.c
+++ b/utils.c
@@ -11,4 +11,5 @@
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 #include <dirent.h>
 #include <utime.h>
@@ -1124,9 +1125,16 @@
 	status = system(cmd);
 
 	if (status == -1)
+	{
 		fprintf(stderr, "Error starting command: %s\n", cmd);
 
-	return status;
+		return -1;
+	}
+
+	if (WIFSIGNALED(status))
+		return 128 + WTERMSIG(status);
+
+	return WEXITSTATUS(status);
 }
 
 

--===============8884418094617090387==--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads