Subject: bin/11107: shar(1) is too forgiving of errors
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dave@dtsp.co.nz>
List: netbsd-bugs
Date: 09/30/2000 20:12:22
>Number:         11107
>Category:       bin
>Synopsis:       shar(1) is too forgiving of errors
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 30 20:18:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Dave Sainty
>Release:        recent NetBSD-current
>Organization:
Dynamic Technology Services and Products Ltd (NZ)
>Environment:
System: NetBSD tequila.dave.dtsp.co.nz 1.5E NetBSD 1.5E (TEQUILA) #3: Sun Sep 10 17:28:10 NZST 2000 dave@tequila.dave.dtsp.co.nz:/vol/tequila/userB/u2/NetBSD-current/src/sys/arch/i386/compile/TEQUILA i386


>Description:
	If shar(1) is called with arguments including filenames that do not
	exist, it still terminates with exit level 0.

	This has an undesirable side-effect that is probably more correctly a
	GNU shar bug.  Using package "archivers/gsharutils", 'gshar' generates
	script that misbehaves in the presence of the NetBSD 'shar'.

>How-To-Repeat:
	cd /tmp
	touch foo
	gshar foo 2>/dev/null | sh
		sed: --print-text-domain-dir: No such file or directory
		x - creating lock directory
		x - SKIPPING foo (file already exists)

	Note the ugly 'sed' error, which is actually generated by shar(1).

>Fix:
The following patch causes shar(1) to abort immediately with 'exit 1' when a
file is not found.  'gshar' will still misbehave if a file
'--print-text-domain-dir' exists, but it isn't clear that 'shar' should be
held responsible for that.

As an added bonus, this patch also fixes some bugs related to special
characters in filesnames (but not all bugs).

--- src/usr.bin/shar/shar.sh.orig       Wed Dec 21 21:42:04 1994
+++ src/usr.bin/shar/shar.sh    Sun Oct  1 16:08:33 2000
@@ -60,13 +60,13 @@
 
 for i
 do
-       if [ -d $i ]; then
-               echo "echo c - $i"
-               echo "mkdir -p $i > /dev/null 2>&1"
+       if [ -d "$i" ]; then
+               echo "echo c - '$i'"
+               echo "mkdir -p './$i' > /dev/null 2>&1"
        else
-               echo "echo x - $i"
-               echo "sed 's/^X//' >$i << 'END-of-$i'"
-               sed 's/^/X/' $i
+               echo "echo x - '$i'"
+               echo "sed 's/^X//' >'$i' << 'END-of-$i'"
+               sed 's/^/X/' "$i" || exit 1
                echo "END-of-$i"
        fi
 done
>Release-Note:
>Audit-Trail:
>Unformatted: