[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Patch for bash



Hello world,

Apparently we need to fix 3 and a bit more release critical bugs than
we open every day from now until November to get potato out the door.
I figured I'd start.

Following is a patch against bash-2.02.1-1.6 that fixes the /bin/sh
overwriting bug, and removes bash's predependency on itself (the bash
preinst is a /bin/sh script).

The changes to the maintainer scripts are as follows:

     * preinst is now a simple C binary (dynamically linked against libc6)
       that has exactly the same functionality as the previous preinst,
       but that doesn't depend on /bin/sh. Note that system() uses /bin/sh
       implicitly, so you have to go to the trouble of fork/exec'ing.

     * postinst is a /bin/bash script instead of a /bin/sh script -- this
       means it won't fail if for some reason there isn't a /bin/sh symlink
       already. If there isn't a symlink (or or an actual file) it makes
       a symlink (using the ln command. it might be better to make this
       an executable too, to remove the (unstated) dependency on fileutils
       (which is, however, essential))

     * prerm is a /bin/bash script instead of a /bin/sh. Just in case.

I also changed the pre-depends/depends stuff so only libc6 is a
pre-dependency.

If you try installing bash on a system without a shell, it runs the
preinst successfully (assuming you have libc6, which is a pre-dependency),
and then runs the postinst successfully (by this time libreadline is
installed and configured and /bin/bash works), after which point you have
a working /bin/sh (either whatever was already there, or a new link to
/bin/bash), a working bash, and everything's fine and dandy.

This fixes bugs #34717, #36016 (or, rather, the problem that causes this
to be necessary), #43050, and #43096, in a non-stop-gap sort of way.

So Guy, would you be willing to apply this patch? Unfortunately, I don't
seem to be able to compile bash properly (the libc5 stuff dies horrible
deaths if I don't comment it out), so I can't offer to make an NMU, but
hopefully someone else on the -qa list would be able to step forward and
do so in the next couple of weeks if you're too busy.

Hope this helps.

----patch----
diff --new-file -urb bash-2.02.1/debian/bash.postinst bash-2.02.1-1.7/debian/bash.postinst
--- bash-2.02.1/debian/bash.postinst	Sat Aug 28 04:04:50 1999
+++ bash-2.02.1-1.7/debian/bash.postinst	Sat Aug 28 04:06:57 1999
@@ -1,4 +1,7 @@
-#! /bin/sh
+#! /bin/bash
 set -e
+
+if [ ! -e /bin/sh ]; then ln -s bash /bin/sh; fi
+
 install-info --quiet --description="GNU Bourne-Again SHell Features." \
  --section "General Commands" "General Commands" /usr/info/bash.info.gz
diff --new-file -urb bash-2.02.1/debian/bash.preinst bash-2.02.1-1.7/debian/bash.preinst
--- bash-2.02.1/debian/bash.preinst	Sat Aug 28 04:04:50 1999
+++ bash-2.02.1-1.7/debian/bash.preinst	Thu Jan  1 10:00:00 1970
@@ -1,4 +0,0 @@
-#!/bin/sh
-set -e
-dpkg --assert-support-predepends ||
-  ( echo -e "\nPlease upgrade to a newer version of dpkg\n"; exit 1 )
diff --new-file -urb bash-2.02.1/debian/bash.preinst.c bash-2.02.1-1.7/debian/bash.preinst.c
--- bash-2.02.1/debian/bash.preinst.c	Thu Jan  1 10:00:00 1970
+++ bash-2.02.1-1.7/debian/bash.preinst.c	Sat Aug 28 01:06:37 1999
@@ -0,0 +1,44 @@
+/* Copyright (c) 1999 Anthony Towns
+ *
+ * You may freely use, distribute, and modify this program.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int main(void) {
+    pid_t child;
+
+    switch(child = fork()) {
+      case -1:
+        /* fork failed */
+        return EXIT_FAILURE;
+
+      case 0: 
+        /* i'm the child */
+        {
+            execl( "/usr/bin/dpkg", "/usr/bin/dpkg",
+                   "--assert-support-predepends", NULL );
+	    return 127;
+        }
+
+      default:
+        /* i'm the parent */
+        {
+            int status;
+            pid_t pid;
+            pid = wait(&status);
+            if (pid == child) {
+                if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+                    return EXIT_SUCCESS;
+                }
+            }
+        }
+    }
+
+    printf("\nPlease upgrade to a new version of dpkg\n\n");
+    return EXIT_FAILURE;
+}
diff --new-file -urb bash-2.02.1/debian/bash.preinst.old bash-2.02.1-1.7/debian/bash.preinst.old
--- bash-2.02.1/debian/bash.preinst.old	Thu Jan  1 10:00:00 1970
+++ bash-2.02.1-1.7/debian/bash.preinst.old	Fri Aug 27 23:39:15 1999
@@ -0,0 +1,4 @@
+#!/bin/sh
+set -e
+dpkg --assert-support-predepends ||
+  ( echo -e "\nPlease upgrade to a newer version of dpkg\n"; exit 1 )
diff --new-file -urb bash-2.02.1/debian/bash.prerm bash-2.02.1-1.7/debian/bash.prerm
--- bash-2.02.1/debian/bash.prerm	Sat Aug 28 04:04:50 1999
+++ bash-2.02.1-1.7/debian/bash.prerm	Sat Aug 28 01:49:34 1999
@@ -1,3 +1,3 @@
-#! /bin/sh
+#! /bin/bash
 set -e
 install-info --quiet --remove bash
diff --new-file -urb bash-2.02.1/debian/changelog bash-2.02.1-1.7/debian/changelog
--- bash-2.02.1/debian/changelog	Sat Aug 28 04:04:50 1999
+++ bash-2.02.1-1.7/debian/changelog	Sat Aug 28 01:50:00 1999
@@ -1,3 +1,17 @@
+bash (2.02.1-1.7) unstable; urgency=low
+
+  * Non-maintainer release.
+
+  * Make bash not Pre-Depend on itself. That is, make bash's preinst
+    something other than a /bin/sh script; in this case a reasonably
+    simple binary.
+
+  * Remove /bin/sh from the .deb, and reinstate it in the postinst if
+    it's not already present. Hence make the postinst a /bin/bash script
+    instead of a /bin/sh script.
+
+ -- Anthony Towns <ajt@debian.org>  Sat, 28 Aug 1999 01:09:08 +1000
+
 bash (2.02.1-1.6) unstable; urgency=low
 
   * Non-maintainer release.
diff --new-file -urb bash-2.02.1/debian/control bash-2.02.1-1.7/debian/control
--- bash-2.02.1/debian/control	Sat Aug 28 04:04:50 1999
+++ bash-2.02.1-1.7/debian/control	Sat Aug 28 01:56:30 1999
@@ -6,7 +6,8 @@
 
 Package: bash
 Architecture: any
-Pre-Depends: ${shlibs:Depends}
+Pre-Depends: ${shlibs:Pre-Depends}
+Depends: ${shlibs:Depends}
 Essential: yes
 Section: base
 Priority: required
diff --new-file -urb bash-2.02.1/debian/rules bash-2.02.1-1.7/debian/rules
--- bash-2.02.1/debian/rules	Sat Aug 28 04:04:50 1999
+++ bash-2.02.1-1.7/debian/rules	Sat Aug 28 04:08:44 1999
@@ -33,6 +33,7 @@
 # which was accidentally non-optimized and an optimized readline.
 	rm lib/readline/{*.o,*.so}
 	$(MAKE) -C lib/readline SOVERSION=$(soversion) CFLAGS=-g libreadline.so libhistory.so
+	cd debian; $(CC) -Wall -W -O2 -s -o bash.preinst bash.preinst.c
 ifdef BUILDLIBC5
 	CONFIG_SITE="" CC=$(CCLIBC1) ./configure --cache-file=configc1.cache --host=$(CONFIGUREHOST) --with-curses
 	test -d lib/readline/libc5 || mkdir lib/readline/libc5
@@ -48,6 +49,7 @@
 	rm -f configc1.cache
 	rm -rf debian/{tmp*,files*,substvars,rl-libc[56].postinst}
 	find . -name '*~' -o -name '*.[oa]' -print0 | xargs -0 rm -f
+	rm -f debian/bash.preinst
 	rm -f core
 
 binary-indep:	checkroot build
@@ -60,7 +62,7 @@
 	install -o 0 -g 0 -d debian/tmp/{DEBIAN,bin,etc/skel,usr/{bin,share/{doc/bash,info,man/man1}}}
 	install -o 0 -g 0 -s bash debian/tmp/bin
 	ln -s bash debian/tmp/bin/rbash
-	ln -s bash debian/tmp/bin/sh
+	# ln -s bash debian/tmp/bin/sh  # -- done in postinst instead
 	ln -s bash.1.gz debian/tmp/usr/share/man/man1/sh.1.gz
 	install -o 0 -g 0 bashbug debian/tmp/usr/bin
 	install -o 0 -g 0 -m 644 debian/etc.profile debian/tmp/etc/profile
@@ -80,7 +82,7 @@
 	install -o 0 -g 0 debian/bash.postinst debian/tmp/DEBIAN/postinst
 	install -o 0 -g 0 debian/bash.prerm debian/tmp/DEBIAN/prerm
 	install -o 0 -g 0 -m 644 debian/bash.conffiles debian/tmp/DEBIAN/conffiles
-	dpkg-shlibdeps bash
+	dpkg-shlibdeps bash -dPre-Depends debian/bash.preinst
 	dpkg-gencontrol -isp -pbash
 	dpkg --build debian/tmp ..
 
----patch----

Cheers,
aj

-- 
Anthony Towns <aj@humbug.org.au> <http://azure.humbug.org.au/~aj/>
I don't speak for anyone save myself. PGP encrypted mail preferred.

 ``The thing is: trying to be too generic is EVIL. It's stupid, it 
        results in slower code, and it results in more bugs.''
                                        -- Linus Torvalds

Attachment: pgpkYzKliSSJP.pgp
Description: PGP signature


Reply to: