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

Bug#697017: [PATCH initramfs-tools 1/3] parse_numeric: Tighten check for whether 'root' parameter is a number



Based on work by Jonathan Nieder.

Closes: #697017
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 scripts/functions | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/scripts/functions b/scripts/functions
index 33fddcf..2da6173 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -103,24 +103,27 @@ load_modules()
 # lilo compatibility
 parse_numeric() {
 	case $1 in
-	"")
-		return
+	*:*)
+		# Does it match /[0-9]*:[0-9]*/?
+		minor=${1#*:}
+		major=${1%:*}
+		case $major$minor in
+		*[!0-9]*)
+			# No.
+			return
+			;;
+		esac
 		;;
-	/*)
+	"" | *[!A-Fa-f0-9]*)
+		# "", "/*", etc.
 		return
 		;;
-	[0-9]*:[0-9]*)
-		minor=$(( ${1#*:} ))
-		major=$(( ${1%:*} ))
-		;;
-	[A-Fa-f0-9]*)
+	*)
+		# [A-Fa-f0-9]*
 		value=$(( 0x${1} ))
 		minor=$(( ${value} % 256 ))
 		major=$(( ${value} / 256 ))
 		;;
-	*)
-		return
-		;;
 	esac
 
 	if command -v udevd >/dev/null 2>&1; then

-- 
Ben Hutchings
Life would be so much easier if we could look at the source code.

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


Reply to: