PATCH: fix bogus "unset" abort in /bin/sh (been pending for TWO YEARS)

From: Matthias Andree <ma_at_dt.e-technik.uni-dortmund.de>
Date: Mon, 20 Sep 2004 21:11:38 +0200
[WARNING: Reply-To and Mail-Followup-To set to funnel the discussion.]

Greetings,

FreeBSD's /bin/sh has a long-standing bug that causes premature abort of
a script when set -e is set and a nonexistant variable is unset.

This violates IEEE Std 1003.1 and harms portability of scripts to FreeBSD.
http://www.opengroup.org/onlinepubs/009695399/utilities/unset.html

Either test of these must print "good" else the shell is b0rked:

/bin/sh -c 'set -e ; BONK= ; unset BONK ; unset BONK ; echo good'
/bin/sh -c 'set -e ; f() { :; } ; unset -f f ; unset -f f ; echo good'

After merging the patch below and MFC'ing, please close standards/45738.

This patch (against 5.3-BETA) fixes the problems for me (yes I know it
is not very helpful without more context but I can't paste half the
files here for the mailing list):

--- src/bin/sh/exec.c.orig	Thu Apr 15 05:08:30 2004
+++ src/bin/sh/exec.c	Sat Sep 18 13:16:34 2004
_at__at_ -701,7 +701,7 _at__at_
 		delete_cmd_entry();
 		return (0);
 	}
-	return (1);
+	return (0);
 }
 
 /*
--- src/bin/sh/var.c.orig	Thu Apr 15 05:08:31 2004
+++ src/bin/sh/var.c	Sat Sep 18 13:16:34 2004
_at__at_ -761,7 +761,7 _at__at_
 		}
 	}
 
-	return (1);
+	return (0);
 }

-- 
Matthias Andree

Encrypted mail welcome: my GnuPG key ID is 0x052E7D95 (PGP/MIME preferred)
Received on Mon Sep 20 2004 - 17:11:46 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:12 UTC