mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
fish: Be stricter about boolean values.
Previously I noticed that bfan used this command without any error:
><fs> hivex-open /WINDOWS/system32/config/software write:ture
^^^^^^^^^^
This was because the code allowed any string to be evaluated as a
boolean.
The new code is stricter. It allows the following strings only case
insensitive (everything else is an error):
1
true
t
yes
y
on
0
false
f
no
n
off
This commit is contained in:
27
fish/fish.c
27
fish/fish.c
@@ -1275,12 +1275,27 @@ print_table (char *const *argv)
|
||||
int
|
||||
is_true (const char *str)
|
||||
{
|
||||
return
|
||||
STRCASENEQ (str, "0") &&
|
||||
STRCASENEQ (str, "f") &&
|
||||
STRCASENEQ (str, "false") &&
|
||||
STRCASENEQ (str, "n") &&
|
||||
STRCASENEQ (str, "no");
|
||||
/* Similar to Tcl_GetBoolean. */
|
||||
|
||||
if (STREQ (str, "1") ||
|
||||
STRCASEEQ (str, "true") ||
|
||||
STRCASEEQ (str, "t") ||
|
||||
STRCASEEQ (str, "yes") ||
|
||||
STRCASEEQ (str, "y") ||
|
||||
STRCASEEQ (str, "on"))
|
||||
return 1;
|
||||
|
||||
if (STREQ (str, "0") ||
|
||||
STRCASEEQ (str, "false") ||
|
||||
STRCASEEQ (str, "f") ||
|
||||
STRCASEEQ (str, "no") ||
|
||||
STRCASEEQ (str, "n") ||
|
||||
STRCASEEQ (str, "off"))
|
||||
return 0;
|
||||
|
||||
fprintf (stderr, _("%s: '%s': invalid boolean value, use 'true' or 'false'\n"),
|
||||
program_name, str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Free strings from a non-NULL terminated char** */
|
||||
|
||||
@@ -440,7 +440,11 @@ Guestfish will prompt for these separately."
|
||||
pr " input_lineno++;\n";
|
||||
pr " if (%s == NULL) goto out_%s;\n" name name
|
||||
| Bool name ->
|
||||
pr " %s = is_true (argv[i++]) ? 1 : 0;\n" name
|
||||
pr " switch (is_true (argv[i++])) {\n";
|
||||
pr " case -1: goto out_%s;\n" name;
|
||||
pr " case 0: %s = 0; break;\n" name;
|
||||
pr " default: %s = 1;\n" name;
|
||||
pr " }\n"
|
||||
| Int name ->
|
||||
let range =
|
||||
let min = "(-(2LL<<30))"
|
||||
@@ -475,8 +479,11 @@ Guestfish will prompt for these separately."
|
||||
pr "if (STRPREFIX (argv[i], \"%s:\")) {\n" n;
|
||||
(match argt with
|
||||
| OBool n ->
|
||||
pr " optargs_s.%s = is_true (&argv[i][%d]) ? 1 : 0;\n"
|
||||
n (len+1);
|
||||
pr " switch (is_true (&argv[i][%d])) {\n" (len+1);
|
||||
pr " case -1: goto out;\n";
|
||||
pr " case 0: optargs_s.%s = 0; break;\n" n;
|
||||
pr " default: optargs_s.%s = 1;\n" n;
|
||||
pr " }\n"
|
||||
| OInt n ->
|
||||
let range =
|
||||
let min = "(-(2LL<<30))"
|
||||
@@ -617,8 +624,9 @@ Guestfish will prompt for these separately."
|
||||
List.iter (
|
||||
function
|
||||
| Device _ | String _
|
||||
| OptString _ | Bool _
|
||||
| OptString _
|
||||
| BufferIn _ -> ()
|
||||
| Bool name
|
||||
| Int name | Int64 name ->
|
||||
pr " out_%s:\n" name
|
||||
| Pathname name | Dev_or_Path name | FileOut name
|
||||
|
||||
Reference in New Issue
Block a user