Bug#484501: grub: Really odd code in savedefault.diff

Samuel Thibault samuel.thibault at ens-lyon.org
Wed Jun 4 12:40:25 UTC 2008


Package: grub
Version: 0.97-39
Severity: normal
Tags: patch

Hello,

I have to admit I fail to understand how the stage2.c part of
savedefault.diff was supposed to work correctly. Here is a patch that
makes it a lot simpler and actually properly working.

Samuel

-- Package-specific info:

*********************** BEGIN /boot/grub/device.map
(hd0)	/dev/hda
(hd1)	/dev/hda6
*********************** END /boot/grub/device.map

*********************** BEGIN /proc/mounts
/dev/root / ext3 rw,noatime,errors=remount-ro,data=ordered 0 0
/dev/root /dev/.static/dev ext3 rw,errors=remount-ro,data=ordered 0 0
/dev/hda1 /mnt/win ntfs ro,uid=1000,gid=100,umask=0222,nls=iso8859-1,errors=continue,mft_zone_multiplier=1 0 0
/dev/hda5 /mnt/goinfre vfat rw,noatime,uid=1000,gid=100,fmask=0002,dmask=0002,codepage=cp850,iocharset=cp850 0 0
/dev/hda4 /mnt/dos vfat rw,fmask=0022,dmask=0022,codepage=cp850,iocharset=cp850 0 0
*********************** END /proc/mounts

*********************** BEGIN /boot/grub/menu.lst
# menu.lst - See: grub(8), info grub, update-grub(8)
#            grub-install(8), grub-floppy(8),
#            grub-md5-crypt, /usr/share/doc/grub
#            and /usr/share/doc/grub-doc/.

#terminal --dumb console

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.           
default		1

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout		5

# Pretty colours
color cyan/blue white/blue

### PASSWORD LINE REMOVED ###
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line)  and entries protected by the
# command 'lock'
### PASSWORD LINE REMOVED ###
### PASSWORD LINE REMOVED ###
### PASSWORD LINE REMOVED ###

#
# examples
#
# title		Windows 95/98/NT/2000
# root		(hd0,0)
# makeactive
# chainloader	+1
#
# title		Linux
# root		(hd0,1)
# kernel	/vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
##      kopt_2_6_8=root=/dev/hdc1 ro
##      kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,1)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
##      alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
##      lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=

## should update-grub lock old automagic boot options
## e.g. lockold=false
##      lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=vga=text-80x50,keep

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0 4

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(single-user) single
# altoptions=(recovery mode) single
# altoptions=(emergency mode) emergency

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
##      howmany=7
# howmany=all

## should update-grub create memtest86 boot option
## e.g. memtest86=true
##      memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## should update-grub add savedefault to the default options
## can be true or false
# savedefault=false

## ## End Default Options ##

title		Xen 3.3 / Debian GNU/Linux, kernel 2.6.18.8
root		(hd0,1)
kernel		/boot/xen-3.3.gz vga=text-80x50,keep
module		/boot/vmlinuz-2.6.18.8 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 console=tty0 4
module		/boot/initrd-2.6.18.8

title		Debian GNU/Linux, kernel 2.6.25
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.25 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 

title		Debian GNU/Linux, kernel 2.6.25 (recovery mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.25 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 single

title		Debian GNU/Linux, kernel 2.6.25 (emergency mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.25 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 emergency

title		Debian GNU/Linux, kernel 2.6.23
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.23 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 

title		Debian GNU/Linux, kernel 2.6.23 (recovery mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.23 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 single

title		Debian GNU/Linux, kernel 2.6.23 (emergency mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.23 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 emergency

title		Debian GNU/Linux, kernel 2.6.18.8
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.18.8 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 
initrd		/boot/initrd-2.6.18.8

title		Debian GNU/Linux, kernel 2.6.18.8 (recovery mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.18.8 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 single
initrd		/boot/initrd-2.6.18.8

title		Debian GNU/Linux, kernel 2.6.18.8 (emergency mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.18.8 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 emergency
initrd		/boot/initrd-2.6.18.8

title		Debian GNU/Linux, kernel 2.6.18-6-686
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.18-6-686 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 
initrd		/boot/initrd.img-2.6.18-6-686

title		Debian GNU/Linux, kernel 2.6.18-6-686 (recovery mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.18-6-686 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 single
initrd		/boot/initrd.img-2.6.18-6-686

title		Debian GNU/Linux, kernel 2.6.18-6-686 (emergency mode)
root		(hd0,1)
kernel		/boot/vmlinuz-2.6.18-6-686 root=/dev/hda2 ro vga=extended lapic video=intelfb:1024x768 nmi_watchdog=0 keyboard.default_leds=2 emergency
initrd		/boot/initrd.img-2.6.18-6-686

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
#title		Other operating systems:
#root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/hda1
title		Microsoft Windows XP Professionnel
unhide		(hd0,0)
hide		(hd0,3)
root		(hd0,0)
makeactive
savedefault
chainloader	+1

title		DOS
unhide		(hd0,3)
hide		(hd0,0)
root		(hd0,3)
makeactive
savedefault
chainloader	+1

title		GNU/Hurd
root		(hd0,5)
kernel		/boot/gnumach.gz root=device:hd0s6
module		/hurd/ext2fs.static -A --multiboot-command-line=${kernel-command-line} --host-priv-port=${host-port} --device-master-port=${device-port} --exec-server-task=${exec-task} -T typed ${root} $(task-create) $(task-resume)
module		/lib/ld.so.1 /hurd/exec $(exec-task=task-create)
boot

title		GNU/Hurd Single
root		(hd0,5)
kernel		/boot/gnumach.gz root=device:hd0s6 -s
module		/hurd/ext2fs.static -A --multiboot-command-line=${kernel-command-line} --host-priv-port=${host-port} --device-master-port=${device-port} --exec-server-task=${exec-task} -T typed ${root} $(task-create) $(task-resume)
module		/lib/ld.so.1 /hurd/exec $(exec-task=task-create)
boot

title		GNU/Hurd orig
root		(hd0,1)
kernel		/usr/src/gnumach-1-rw/gnumach.orig root=device:hd0s6
root		(hd0,5)
module		/hurd/ext2fs.static -A --multiboot-command-line=${kernel-command-line} --host-priv-port=${host-port} --device-master-port=${device-port} --exec-server-task=${exec-task} -T typed ${root} $(task-create) $(task-resume)
module		/lib/ld.so.1 /hurd/exec $(exec-task=task-create)
boot

title		GNU/Hurd test
root		(hd0,1)
kernel		/usr/src/gnumach-1-rw/gnumach root=device:hd0s6
root		(hd0,5)
module		/hurd/ext2fs.static -A --multiboot-command-line=${kernel-command-line} --host-priv-port=${host-port} --device-master-port=${device-port} --exec-server-task=${exec-task} -T typed ${root} $(task-create) $(task-resume)
module		/lib/ld.so.1 /hurd/exec $(exec-task=task-create)
boot

title		hda8
root		(hd0,7)
chainloader	+1

title debinst
root		(hd0,1)
kernel		/home/samy/local/installer/build/dest/netboot/debian-installer/i386/2.6/linux vga=normal ramdisk_size=10166 root=/dev/ram rw --
initrd		/home/samy/local/installer/build/dest/netboot/debian-installer/i386/2.6/initrd.gz
boot
	
title debinst-brltty
root		(hd0,1)
kernel		/home/samy/local/installer/build/dest/netboot/debian-installer/i386/2.6/linux vga=normal ramdisk_size=10166 root=/dev/ram rw -- brltty
initrd		/home/samy/local/installer/build/dest/netboot/debian-installer/i386/2.6/initrd.gz
boot
	
title debinst hd-media
root		(hd0,1)
kernel		/home/samy/local/installer/build/dest/hd-media/2.6/vmlinuz vga=normal ramdisk_size=10166 root=/dev/ram rw -- debian-installer/probe/usb=true preseed/file=/floppy/preseed.cfg
initrd		/home/samy/local/installer/build/dest/hd-media/2.6/initrd.gz
boot

title	funk
root	(hd0,1)
kernel	/home/samy/ens/funk/trunk/src/kernel/funk-i686-0.1.0
savedefault
boot

title CD
root (hd0,1)
kernel /boot/grub/memdisk.bin
initrd /boot/grub/sbootmgr.dsk

title	halt
halt

*********************** END /boot/grub/menu.lst

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.25
Locale: LANG=fr_FR at euro, LC_CTYPE=fr_FR at euro (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages grub depends on:
ii  grub-common              1.96+20080512-1 GRand Unified Bootloader, version 
ii  libc6                    2.7-10          GNU C Library: Shared libraries
ii  libncurses5              5.6+20080308-1  Shared libraries for terminal hand

grub recommends no packages.

-- no debconf information

-- 
Samuel
<s> on se croirait en cool : Some browsers close comments on the first ">" character, so to hide script content from such browsers, you can transpose operands for relational and shift operators (e.g., use "y < x" rather than "x > y") or use scripting language-dependent escapes for ">".
 -+- #ens-mim -+-
-------------- next part --------------
--- debian/patches/savedefault.diff.orig	2008-06-04 13:32:19.000000000 +0100
+++ debian/patches/savedefault.diff	2008-06-04 13:37:02.000000000 +0100
@@ -160,22 +160,14 @@
 diff -uNr grub-0.97.orig/stage2/stage2.c grub-0.97/stage2/stage2.c
 --- grub-0.97.orig/stage2/stage2.c	2005-03-19 17:51:57.000000000 +0000
 +++ grub-0.97/stage2/stage2.c	2007-03-06 22:17:55.000000000 +0000
-@@ -891,8 +891,16 @@
+@@ -891,7 +891,10 @@
  	      len = grub_read (buf, sizeof (buf));
  	      if (len > 0)
  		{
--		  buf[sizeof (buf) - 1] = 0;
--		  safe_parse_maxint (&p, &saved_entryno);
 +		  char *tmp;
-+		  char *def;
+ 		  buf[sizeof (buf) - 1] = 0;
 +		  if((tmp = grub_strstr(p, ":")) != NULL)
-+		  {
-+		    *tmp++;
-+		    grub_strcpy(&def, &tmp);
-+		  }else
-+		    grub_strcpy(&def, &p);
-+		  
-+		  safe_parse_maxint (&def, &saved_entryno);
++		    p = tmp+1;
+ 		  safe_parse_maxint (&p, &saved_entryno);
  		}
  
- 	      grub_close ();


More information about the Pkg-grub-devel mailing list