From cejkar@fit.vutbr.cz  Mon Jun 16 08:04:07 2003
Return-Path: <cejkar@fit.vutbr.cz>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id C3ADB37B401; Mon, 16 Jun 2003 08:04:07 -0700 (PDT)
Received: from kazi.fit.vutbr.cz (kazi.fit.vutbr.cz [147.229.8.12])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 92A7843F85; Mon, 16 Jun 2003 08:04:06 -0700 (PDT)
	(envelope-from cejkar@fit.vutbr.cz)
Received: from kazi.fit.vutbr.cz (localhost [127.0.0.1])
	by kazi.fit.vutbr.cz (8.12.9/8.12.9) with ESMTP id h5GF43Ca089480
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO);
	Mon, 16 Jun 2003 17:04:03 +0200 (CEST)
Received: (from cejkar@localhost)
	by kazi.fit.vutbr.cz (8.12.9/8.12.5/Submit) id h5GF43CC089479;
	Mon, 16 Jun 2003 17:04:03 +0200 (CEST)
Message-Id: <200306161504.h5GF43CC089479@kazi.fit.vutbr.cz>
Date: Mon, 16 Jun 2003 17:04:03 +0200 (CEST)
From: Cejka Rudolf <cejkar@fit.vutbr.cz>
Reply-To: Cejka Rudolf <cejkar@fit.vutbr.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc: markm@freebsd.org
Subject: [PATCH] su does not return exit status of executed command
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         53377
>Category:       bin
>Synopsis:       [PATCH] su does not return exit status of executed command
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 16 08:10:05 PDT 2003
>Closed-Date:    Sat Jun 09 18:56:51 GMT 2007
>Last-Modified:  Sat Jun 09 18:56:51 GMT 2007
>Originator:     Rudolf Cejka
>Release:        FreeBSD 5.1-RELEASE i386
>Organization:
FIT, Brno University of Technology, Czech Republic
>Environment:

FreeBSD 5.1-RELEASE FreeBSD 5.1-RELEASE #0: Tue Jun 10 14:27:40 CEST 2003
and all 5.x systems.

>Description:

Command su does not return exit status of executed commands. It returns
0 (or maybe "undefined value"), because there is directly called
exit(statusp) without any statusp conversion returned from waitpid().

This bug for example breaks error detections in scripts on some
systems like my...

The problem is since su.c:1.36, so all 5.x systems are affected.

>How-To-Repeat:

# su -m root -c "true" ; echo $?
0
# su -m root -c "false" ; echo $?
0                                               # should be 1
# su -m root -c "exit 63" ; echo $?
0                                               # should be 63

>Fix:

$ FreeBSD: src/usr.bin/su/su.c,v 1.68 2003/04/08 16:59:53 des Exp $

--- su.c.orig	Mon Jun 16 16:35:22 2003
+++ su.c	Mon Jun 16 16:46:17 2003
@@ -378,7 +378,7 @@
 		if (pid == -1)
 			err(1, "waitpid");
 		PAM_END();
-		exit(statusp);
+		exit(WEXITSTATUS(statusp));
 	case -1:
 		err(1, "fork");
 		PAM_END();

>Release-Note:
>Audit-Trail:

From: Ceri Davies <ceri@FreeBSD.org>
To: FreeBSD Gnats Submit <freebsd-gnats-submit@FreeBSD.org>
Cc:  
Subject: Re: bin/53377: [PATCH] su does not return exit status of executed command
Date: Mon, 16 Jun 2003 23:03:51 +0100

 Adding to audit trail, from misfiled PR bin/53380:
 
 Date: Mon, 16 Jun 2003 16:56:21 +0100
 From: Mark Murray <mark@grondar.org>
 Message-Id: <200306161556.h5GFuMHh089570@grimreaper.grondar.org>
 
  Hi
  
  Thanks! I have a clean-up of su(8) (uncommitted, and I'm incorporating
  this in it.
  
  M
  
  Cejka Rudolf writes:
  > >Fix:
  > 
  > $ FreeBSD: src/usr.bin/su/su.c,v 1.68 2003/04/08 16:59:53 des Exp $
  > 
  > --- su.c.orig	Mon Jun 16 16:35:22 2003
  > +++ su.c	Mon Jun 16 16:46:17 2003
  > @@ -378,7 +378,7 @@
  >  		if (pid == -1)
  >  			err(1, "waitpid");
  >  		PAM_END();
  > -		exit(statusp);
  > +		exit(WEXITSTATUS(statusp));
  >  	case -1:
  >  		err(1, "fork");
  >  		PAM_END();
  
  M
  --
  Mark Murray
  iumop ap!sdn w,I idlaH
 
State-Changed-From-To: open->patched 
State-Changed-By: bms 
State-Changed-When: Mon Jun 14 21:43:40 GMT 2004 
State-Changed-Why:  
This is already in CURRENT 

http://www.freebsd.org/cgi/query-pr.cgi?pr=53377 
State-Changed-From-To: patched->closed 
State-Changed-By: gavin 
State-Changed-When: Sat Jun 9 18:56:34 UTC 2007 
State-Changed-Why:  
Fixed in all supported FreeBSD releases 

http://www.freebsd.org/cgi/query-pr.cgi?pr=53377 
>Unformatted:
