Skip to contentSkip to conversation

ktest: Add support for meta characters in GRUB_MENU

PATCH Superseded Masayoshi Mizuma 3 participants 4 messages Apr 17, 2019 Ktest

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ktest: Add support for meta characters in GRUB_MENU

From: Masayoshi Mizuma <[email protected]>

ktest fails if meta characters are in GRUB_MENU, for example GRUB_MENU = 'Fedora (test)'

The failure happens because the meta characters are not escaped, so the menu doesn't match in any entries in GRUB_FILE.

Use quotameta() to escape the meta characters.

---
 tools/testing/ktest/ktest.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/ktest/ktest.pl +4 -2
index 87af8a68ab25..ea07d43856b8 100755
@@ -1866,9 +1866,10 @@ sub get_grub2_index {
 	or dodie "unable to get $grub_file";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);
 
     while (<IN>) {
-	if (/^menuentry.*$grub_menu/) {
+	if (/^menuentry.*$_grub_menu/) {
 	    $grub_number++;
 	    $found = 1;
 	    last;
@@ -1909,9 +1910,10 @@ sub get_grub_index {
 	or dodie "unable to get menu.lst";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);
 
     while (<IN>) {
-	if (/^\s*title\s+$grub_menu\s*$/) {
+	if (/^\s*title\s+$_grub_menu\s*$/) {
 	    $grub_number++;
 	    $found = 1;
 	    last;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 5 lines · On Wed, 17 Apr 2019 16:11:14 -0400 Masayoshi Mizuma <[email protected]>…

From: Masayoshi Mizuma <[email protected]>

ktest fails if meta characters are in GRUB_MENU, for example GRUB_MENU = 'Fedora (test)'

Thanks for the patch! One little nit below though.

Quoted 15 lines

The failure happens because the meta characters are not escaped, so the menu doesn't match in any entries in GRUB_FILE.

Use quotameta() to escape the meta characters.

---
 tools/testing/ktest/ktest.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/ktest/ktest.pl +0 -0
index 87af8a68ab25..ea07d43856b8 100755

tools/testing/ktest/ktest.pl sub get_grub2_index { · line 1869

Quoted 4 lines
tools/testing/ktest/ktest.pl +1 -0
@@ -1866,9 +1866,10 @@ sub get_grub2_index {
 	or dodie "unable to get $grub_file";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);

I'd like to avoid names that start with underscore. Could you call this:

$grub_menu_qt

or something similar, to be a bit more descriptive of what the variable is.

Thanks!

-- Steve

Quoted 19 lines
tools/testing/ktest/ktest.pl +3 -2
     while (<IN>) {
-	if (/^menuentry.*$grub_menu/) {
+	if (/^menuentry.*$_grub_menu/) {
 	    $grub_number++;
 	    $found = 1;
 	    last;
@@ -1909,9 +1910,10 @@ sub get_grub_index {
 	or dodie "unable to get menu.lst";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);
 
     while (<IN>) {
-	if (/^\s*title\s+$grub_menu\s*$/) {
+	if (/^\s*title\s+$_grub_menu\s*$/) {
 	    $grub_number++;
 	    $found = 1;
 	    last;
#2 lore raw
Quoted 33 lines · Steven Rostedt
Quoted 5 lines · On Wed, 17 Apr 2019 16:11:14 -0400 Masayoshi Mizuma <[email protected]>…

From: Masayoshi Mizuma <[email protected]>

ktest fails if meta characters are in GRUB_MENU, for example GRUB_MENU = 'Fedora (test)'

Thanks for the patch! One little nit below though.

Quoted 15 lines

The failure happens because the meta characters are not escaped, so the menu doesn't match in any entries in GRUB_FILE.

Use quotameta() to escape the meta characters.

---
 tools/testing/ktest/ktest.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/ktest/ktest.pl +0 -0
index 87af8a68ab25..ea07d43856b8 100755

tools/testing/ktest/ktest.pl sub get_grub2_index { · line 1869

Quoted 4 lines
tools/testing/ktest/ktest.pl +1 -0
@@ -1866,9 +1866,10 @@ sub get_grub2_index {
 	or dodie "unable to get $grub_file";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);

I'd like to avoid names that start with underscore. Could you call this:

Quoted 4 lines

$grub_menu_qt

or something similar, to be a bit more descriptive of what the variable is.

Thank you for your review! I'll fix it and post the v2.

Thanks!
Masa

#3 lore raw
In reply to Masayoshi Mizuma
Quoted 9 lines · Masayoshi Mizuma

From: Masayoshi Mizuma <[email protected]>

ktest fails if meta characters are in GRUB_MENU, for example GRUB_MENU = 'Fedora (test)'

The failure happens because the meta characters are not escaped, so the menu doesn't match in any entries in GRUB_FILE.

Use quotameta() to escape the meta characters.

Use quotemeta()

Quoted 35 lines
---
 tools/testing/ktest/ktest.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/ktest/ktest.pl +4 -2
index 87af8a68ab25..ea07d43856b8 100755
@@ -1866,9 +1866,10 @@ sub get_grub2_index {
 	or dodie "unable to get $grub_file";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);
 
     while (<IN>) {
-	if (/^menuentry.*$grub_menu/) {
+	if (/^menuentry.*$_grub_menu/) {
 	    $grub_number++;
 	    $found = 1;
 	    last;
@@ -1909,9 +1910,10 @@ sub get_grub_index {
 	or dodie "unable to get menu.lst";
 
     my $found = 0;
+    my $_grub_menu = quotemeta($grub_menu);
 
     while (<IN>) {
-	if (/^\s*title\s+$grub_menu\s*$/) {
+	if (/^\s*title\s+$_grub_menu\s*$/) {
 	    $grub_number++;
 	    $found = 1;
 	    last;
Signature · 1 line
~Randy