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

[PATCH initramfs-tools 2/5] init: Fix validation of the real init program



If /sbin/init is executable then we would ignore that $init was
invalid, without actually setting init=/sbin/init.

$init is initialised to /sbin/init, so don't skip the error
message if it's empty.

Related-to: #763157
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 init | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/init b/init
index 05394c2..b47bf7a 100755
--- a/init
+++ b/init
@@ -242,25 +242,16 @@ validate_init() {
 	fi
 }
 
-# Check init bootarg
-if [ -n "${init}" ]; then
-	if ! validate_init "$init"; then
-		echo "Target filesystem doesn't have requested ${init}."
-		init=
-	fi
-fi
-
-# Common case: /sbin/init is present
-if [ ! -x "${rootmnt}/sbin/init" ]; then
-	# ... if it's not available search for valid init
-	if [ -z "${init}" ] ; then
-		for inittest in /sbin/init /etc/init /bin/init /bin/sh; do
-			if validate_init "${inittest}"; then
-				init="$inittest"
-				break
-			fi
-		done
-	fi
+# Check init is really there
+if ! validate_init "$init"; then
+	echo "Target filesystem doesn't have requested ${init}."
+	init=
+	for inittest in /sbin/init /etc/init /bin/init /bin/sh; do
+		if validate_init "${inittest}"; then
+			init="$inittest"
+			break
+		fi
+	done
 fi
 
 if read_fstab_entry /usr; then


-- 
Ben Hutchings
Logic doesn't apply to the real world. - Marvin Minsky

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: