|
|
f96e0b |
From 568a5bef7e6b7309a652b328d65a9964b6d415e5 Mon Sep 17 00:00:00 2001
|
|
|
f96e0b |
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
Date: Sat, 4 May 2013 13:38:59 +0200
|
|
|
f96e0b |
Subject: [PATCH 415/482] Fix test -a and -o precedence. Reported by:
|
|
|
f96e0b |
adrian15.
|
|
|
f96e0b |
|
|
|
f96e0b |
---
|
|
|
f96e0b |
ChangeLog | 5 +++++
|
|
|
f96e0b |
Makefile.util.def | 6 ++++++
|
|
|
f96e0b |
grub-core/commands/test.c | 30 ++++++++++++++----------------
|
|
|
f96e0b |
tests/grub_script_test.in | 15 +++++++++++++++
|
|
|
f96e0b |
4 files changed, 40 insertions(+), 16 deletions(-)
|
|
|
f96e0b |
create mode 100644 tests/grub_script_test.in
|
|
|
f96e0b |
|
|
|
f96e0b |
diff --git a/ChangeLog b/ChangeLog
|
|
|
f96e0b |
index a721215..7a7d11c 100644
|
|
|
f96e0b |
--- a/ChangeLog
|
|
|
f96e0b |
+++ b/ChangeLog
|
|
|
f96e0b |
@@ -1,5 +1,10 @@
|
|
|
f96e0b |
2013-05-04 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
|
|
|
f96e0b |
+ Fix test -a and -o precedence.
|
|
|
f96e0b |
+ Reported by: adrian15.
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+2013-05-04 Vladimir Serbinenko <phcoder@gmail.com>
|
|
|
f96e0b |
+
|
|
|
f96e0b |
* grub-core/font/font.c (grub_font_construct_glyph): Fix memory leak.
|
|
|
f96e0b |
|
|
|
f96e0b |
2013-05-03 Andrey Borzenkov <arvidjaar@gmail.com>
|
|
|
f96e0b |
diff --git a/Makefile.util.def b/Makefile.util.def
|
|
|
f96e0b |
index a357341..d0ae67f 100644
|
|
|
f96e0b |
--- a/Makefile.util.def
|
|
|
f96e0b |
+++ b/Makefile.util.def
|
|
|
f96e0b |
@@ -583,6 +583,12 @@ script = {
|
|
|
f96e0b |
|
|
|
f96e0b |
script = {
|
|
|
f96e0b |
testcase;
|
|
|
f96e0b |
+ name = grub_script_test;
|
|
|
f96e0b |
+ common = tests/grub_script_test.in;
|
|
|
f96e0b |
+};
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+script = {
|
|
|
f96e0b |
+ testcase;
|
|
|
f96e0b |
name = grub_script_echo1;
|
|
|
f96e0b |
common = tests/grub_script_echo1.in;
|
|
|
f96e0b |
};
|
|
|
f96e0b |
diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c
|
|
|
f96e0b |
index e3347ee..c98c13d 100644
|
|
|
f96e0b |
--- a/grub-core/commands/test.c
|
|
|
f96e0b |
+++ b/grub-core/commands/test.c
|
|
|
f96e0b |
@@ -41,7 +41,8 @@ grub_strtosl (char *arg, char **end, int base)
|
|
|
f96e0b |
/* Context for test_parse. */
|
|
|
f96e0b |
struct test_parse_ctx
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- int ret, discard, invert;
|
|
|
f96e0b |
+ int invert;
|
|
|
f96e0b |
+ int or, and;
|
|
|
f96e0b |
int file_exists;
|
|
|
f96e0b |
struct grub_dirhook_info file_info;
|
|
|
f96e0b |
char *filename;
|
|
|
f96e0b |
@@ -51,9 +52,8 @@ struct test_parse_ctx
|
|
|
f96e0b |
static void
|
|
|
f96e0b |
update_val (int val, struct test_parse_ctx *ctx)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- if (! ctx->discard)
|
|
|
f96e0b |
- ctx->ret = ctx->invert ? ! val : val;
|
|
|
f96e0b |
- ctx->invert = ctx->discard = 0;
|
|
|
f96e0b |
+ ctx->and = ctx->and && (ctx->invert ? ! val : val);
|
|
|
f96e0b |
+ ctx->invert = 0;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
/* A hook for iterating directories. */
|
|
|
f96e0b |
@@ -153,8 +153,8 @@ static int
|
|
|
f96e0b |
test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
struct test_parse_ctx ctx = {
|
|
|
f96e0b |
- .ret = 0,
|
|
|
f96e0b |
- .discard = 0,
|
|
|
f96e0b |
+ .and = 1,
|
|
|
f96e0b |
+ .or = 0,
|
|
|
f96e0b |
.invert = 0
|
|
|
f96e0b |
};
|
|
|
f96e0b |
|
|
|
f96e0b |
@@ -332,7 +332,7 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
get_fileinfo (args[*argn + 1], &ctx;;
|
|
|
f96e0b |
update_val (ctx.file_exists && ctx.file_info.dir, &ctx;;
|
|
|
f96e0b |
(*argn) += 2;
|
|
|
f96e0b |
- return ctx.ret;
|
|
|
f96e0b |
+ return ctx.or || ctx.and;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], "-e") == 0)
|
|
|
f96e0b |
@@ -340,7 +340,7 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
get_fileinfo (args[*argn + 1], &ctx;;
|
|
|
f96e0b |
update_val (ctx.file_exists, &ctx;;
|
|
|
f96e0b |
(*argn) += 2;
|
|
|
f96e0b |
- return ctx.ret;
|
|
|
f96e0b |
+ return ctx.or || ctx.and;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], "-f") == 0)
|
|
|
f96e0b |
@@ -349,7 +349,7 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
/* FIXME: check for other types. */
|
|
|
f96e0b |
update_val (ctx.file_exists && ! ctx.file_info.dir, &ctx;;
|
|
|
f96e0b |
(*argn) += 2;
|
|
|
f96e0b |
- return ctx.ret;
|
|
|
f96e0b |
+ return ctx.or || ctx.and;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], "-s") == 0)
|
|
|
f96e0b |
@@ -362,7 +362,7 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
grub_file_close (file);
|
|
|
f96e0b |
grub_errno = GRUB_ERR_NONE;
|
|
|
f96e0b |
(*argn) += 2;
|
|
|
f96e0b |
- return ctx.ret;
|
|
|
f96e0b |
+ return ctx.or || ctx.and;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
/* String tests. */
|
|
|
f96e0b |
@@ -387,7 +387,7 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], ")") == 0)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
(*argn)++;
|
|
|
f96e0b |
- return ctx.ret;
|
|
|
f96e0b |
+ return ctx.or || ctx.and;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
/* Recursively invoke if parenthesis. */
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], "(") == 0)
|
|
|
f96e0b |
@@ -405,15 +405,13 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
}
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], "-a") == 0)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- /* If current value is 0 second value is to be discarded. */
|
|
|
f96e0b |
- ctx.discard = ! ctx.ret;
|
|
|
f96e0b |
(*argn)++;
|
|
|
f96e0b |
continue;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
if (grub_strcmp (args[*argn], "-o") == 0)
|
|
|
f96e0b |
{
|
|
|
f96e0b |
- /* If current value is 1 second value is to be discarded. */
|
|
|
f96e0b |
- ctx.discard = ctx.ret;
|
|
|
f96e0b |
+ ctx.or = ctx.or || ctx.and;
|
|
|
f96e0b |
+ ctx.and = 1;
|
|
|
f96e0b |
(*argn)++;
|
|
|
f96e0b |
continue;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
@@ -422,7 +420,7 @@ test_parse (char **args, int *argn, int argc)
|
|
|
f96e0b |
update_val (args[*argn][0], &ctx;;
|
|
|
f96e0b |
(*argn)++;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
- return ctx.ret;
|
|
|
f96e0b |
+ return ctx.or || ctx.and;
|
|
|
f96e0b |
}
|
|
|
f96e0b |
|
|
|
f96e0b |
static grub_err_t
|
|
|
f96e0b |
diff --git a/tests/grub_script_test.in b/tests/grub_script_test.in
|
|
|
f96e0b |
new file mode 100644
|
|
|
f96e0b |
index 0000000..34a5f14
|
|
|
f96e0b |
--- /dev/null
|
|
|
f96e0b |
+++ b/tests/grub_script_test.in
|
|
|
f96e0b |
@@ -0,0 +1,15 @@
|
|
|
f96e0b |
+#! @builddir@/grub-shell-tester
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+for device in 'hd0' 'fd0'; do
|
|
|
f96e0b |
+ # But search them if their search has been inforced
|
|
|
f96e0b |
+ set fd0search="no"
|
|
|
f96e0b |
+ if [ "$device" != "fd0" -a "$device" != "cd" \
|
|
|
f96e0b |
+ -o \
|
|
|
f96e0b |
+ "$device" = "fd0" -a "$fd0search" = "yes" ]\
|
|
|
f96e0b |
+ ; then
|
|
|
f96e0b |
+ echo "Yes"
|
|
|
f96e0b |
+ else
|
|
|
f96e0b |
+ echo "No"
|
|
|
f96e0b |
+ fi
|
|
|
f96e0b |
+
|
|
|
f96e0b |
+done
|
|
|
f96e0b |
\ No newline at end of file
|
|
|
f96e0b |
--
|
|
|
f96e0b |
1.8.2.1
|
|
|
f96e0b |
|