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

Bug#772901: os-prober wrong output with grep 2.21 or later



Package: os-prober
Version: 1.65
Tags: patch

os-prober uses 'grep' in an unportable way, in that it assumes that the regular expression "." matches the NUL byte (all zero bits). POSIX doesn't guarantee this, and as of grep 2.21 this might not work. If os-prober assumes GNU grep the fix should be fairly straightforward; please see the attached (untested) patch. If os-prober is intended to be portable to non-GNU grep, more hacking will be needed, as POSIX says grep has undefined behavior when given binary input data.

For more details about this issue please see:

https://bugzilla.redhat.com/show_bug.cgi?id=1172405
https://bugzilla.redhat.com/show_bug.cgi?id=1172804
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19348
diff -pru os-prober/os-probes/mounted/x86/20microsoft os-prober-fix/os-probes/mounted/x86/20microsoft
--- os-prober/os-probes/mounted/x86/20microsoft	2014-11-12 07:19:18.000000000 -0800
+++ os-prober-fix/os-probes/mounted/x86/20microsoft	2014-12-11 19:25:06.749770598 -0800
@@ -31,19 +31,19 @@ if item_in_dir -q bootmgr "$2"; then
 	for boot in $(item_in_dir boot "$2"); do
 		bcd=$(item_in_dir bcd "$2/$boot")
 		if [ -n "$bcd" ]; then
-			if grep -qs "W.i.n.d.o.w.s. .8" "$2/$boot/$bcd"; then
+			if grep -aqs "W.i.n.d.o.w.s. .8" "$2/$boot/$bcd"; then
 				long="Windows 8 (loader)"
-			elif grep -qs "W.i.n.d.o.w.s. .7" "$2/$boot/$bcd"; then
+			elif grep -aqs "W.i.n.d.o.w.s. .7" "$2/$boot/$bcd"; then
 				long="Windows 7 (loader)"
-			elif grep -qs "W.i.n.d.o.w.s. .V.i.s.t.a" "$2/$boot/$bcd"; then
+			elif grep -aqs "W.i.n.d.o.w.s. .V.i.s.t.a" "$2/$boot/$bcd"; then
 				long="Windows Vista (loader)"
-			elif grep -qs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8. .R.2." "$2/$boot/$bcd"; then
+			elif grep -aqs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8. .R.2." "$2/$boot/$bcd"; then
 				long="Windows Server 2008 R2 (loader)"
-			elif grep -qs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8." "$2/$boot/$bcd"; then
+			elif grep -aqs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8." "$2/$boot/$bcd"; then
 				long="Windows Server 2008 (loader)"
-			elif grep -qs "W.i.n.d.o.w.s. .R.e.c.o.v.e.r.y. .E.n.v.i.r.o.n.m.e.n.t" "$2/$boot/$bcd"; then
+			elif grep -aqs "W.i.n.d.o.w.s. .R.e.c.o.v.e.r.y. .E.n.v.i.r.o.n.m.e.n.t" "$2/$boot/$bcd"; then
 				long="Windows Recovery Environment (loader)"
-			elif grep -qs "W.i.n.d.o.w.s. .S.e.t.u.p" "$2/$boot/$bcd"; then
+			elif grep -aqs "W.i.n.d.o.w.s. .S.e.t.u.p" "$2/$boot/$bcd"; then
 				long="Windows Recovery Environment (loader)"
 			else
 				long="Windows Vista (loader)"
diff -pru os-prober/os-probes/mounted/x86/83haiku os-prober-fix/os-probes/mounted/x86/83haiku
--- os-prober/os-probes/mounted/x86/83haiku	2014-09-28 14:04:17.000000000 -0700
+++ os-prober-fix/os-probes/mounted/x86/83haiku	2014-12-11 19:32:45.177765083 -0800
@@ -13,7 +13,7 @@ case "$type" in
 	*) debug "$partition is not a BeFS partition: exiting"; exit 1 ;;
 esac
 
-if head -c 512 "$partition" | grep -qs "system.haiku_loader"; then
+if head -c 512 "$partition" | grep -aqs "system.haiku_loader"; then
 	debug "Stage 1 bootloader found"
 else
 	debug "Stage 1 bootloader not found: exiting"

Reply to: