40grub2 incorrectly extracts title from grub.cfg entries that contain more than two single quotes

Bug #1251926 reported by n.st
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
os-prober (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

When linux-boot-prober (from os-prober 1.51ubuntu3 on Ubuntu 12.04.3) finds a grub.cfg containing a line like

menuentry 'Gentoo GNU/Linux, with Linux x86_64-3.8.13-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-3.8.13-gentoo-advanced-eb397f81-2ff4-4751-9c95-39c1e9427a6d' {

and runs /linux-boot-probes/mounted/common/40grub2 to parse it, it will return

/dev/sda4:/dev/sda4:Gentoo GNU/Linux, with Linux x86_64-3.8.13-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-3.8.13-gentoo-advanced-eb397f81-2ff4-4751-9c95-39c1e9427a6d:/boot/kernel-genkernel-x86_64-3.10.17-gentoo:/boot/initramfs-genkernel-x86_64-3.10.17-gentoo:root=UUID=eb397f81-2ff4-4751-9c95-39c1e9427a6d ro

where
Gentoo GNU/Linux, with Linux x86_64-3.8.13-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-x86_64-3.8.13-gentoo-advanced-eb397f81-2ff4-4751-9c95-39c1e9427a6d
is the title (which should just be "Gentoo GNU/Linux, with Linux x86_64-3.8.13-gentoo" instead).

Apparently, the regex used by 40grub2 is too greedy and matches everything between the two outermost single quotes, instead of the first two. The same will probably happen with entries where the title is enclosed in double quotes and more than two of those are present, but I haven't observed it yet.

I have attached a patch for 40grub2 that modifies the regex to stop at the first occurence of a single quote for titles enclosed in single quotes and the first double quote for titles enclosed in double quotes.
Note that this might fail in the rare case of someone using escaped quotes in their GRUB menuentry titles (although I'm not entirely sure if that's even supported).

Revision history for this message
n.st (n.st) wrote :
Revision history for this message
n.st (n.st) wrote :
Changed in os-prober (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.