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

Bug#684611: busybox fails to parse less-than-3-component linux version string



Source: busybox
Version: 1:1.20.0-5
Severity: important
Tags: patch upstream
Forwarded: https://bugs.busybox.net/show_bug.cgi?id=5444

Busybox have the same issue with 2-component linux version code as
lots of other utils had (discovered when linux 3.0 were released):
it just segfaults when such a kernel is used.

This does not affect wheezy directly, since wheezy uses 3.2.0 kernel
(with fake trailing zero to work around exactly this problem in
various software), but yet it is important to get this fixed for
wheezy, to let backported and self-compiled kernels to work.
Especially since busybox is used in initramfs to boot the system.

Patch to fix this issue is below.

/mjt

Subject: allow less-than-3-component kernel version number
From: Michael Tokarev <mjt@tls.msk.ru>
Forwarded: https://bugs.busybox.net/show_bug.cgi?id=5444

Busybox expects at least 3-component linux version number,
and segfaults if less than 3 components are available.

--- debian.orig/libbb/kernel_version.c
+++ debian/libbb/kernel_version.c
@@ -21,18 +21,19 @@
 {
 	struct utsname name;
 	char *s;
-	int i, r;
+	int r;
  	if (uname(&name) == -1) {
 		bb_perror_msg("can't get system information");
 		return 0;
 	}
 -	s = name.release;
-	r = 0;
-	for (i = 0; i < 3; i++) {
-		r = r * 256 + atoi(strtok(s, "."));
-		s = NULL;
+	r = atoi(strtok(name.release, ".")) * 256 * 256;
+	if ((s = strtok(NULL, ".")) != NULL) {
+		r |= atoi(s) * 256;
+		if ((s = strtok(NULL, ".")) != NULL)
+			r |= atoi(s);
 	}
+
 	return r;
 }


Reply to: