From 9e196cc2902255c328a90584e44666b79e4344c3 Mon Sep 17 00:00:00 2001 From: Phillip Susi Date: Thu, 10 May 2018 12:31:36 -0400 Subject: [PATCH 85/92] Fix set and disk_set to not crash when no flags are supported Loop labels and file images support no flags. set and disk_set would prompt for a flag and accept any string since the list of flags was empty, then fail to look up an actual flag value, then throw an exception with a null string for the name of the flag, which would bug. --- parted/ui.c | 18 ++++++++++++++++-- tests/t3310-flags.sh | 13 +++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/parted/ui.c b/parted/ui.c index 752860b..4f42b7c 100644 --- a/parted/ui.c +++ b/parted/ui.c @@ -1150,7 +1150,14 @@ command_line_get_disk_flag (const char* prompt, const PedDisk* disk, opts = str_list_append_unique (opts, _(walk_name)); } } - + if (opts == NULL) + { + ped_exception_throw (PED_EXCEPTION_ERROR, + PED_EXCEPTION_OK, + _("No flags supported")); + + return 0; + } flag_name = command_line_get_word (prompt, NULL, opts, 1); str_list_destroy (opts); @@ -1179,7 +1186,14 @@ command_line_get_part_flag (const char* prompt, const PedPartition* part, opts = str_list_append_unique (opts, _(walk_name)); } } - + if (opts == NULL) + { + ped_exception_throw (PED_EXCEPTION_ERROR, + PED_EXCEPTION_OK, + _("No flags supported")); + + return 0; + } flag_name = command_line_get_word (prompt, NULL, opts, 1); str_list_destroy (opts); diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh index 2da72d0..0997748 100644 --- a/tests/t3310-flags.sh +++ b/tests/t3310-flags.sh @@ -114,4 +114,17 @@ for table_type in aix amiga atari bsd dvh gpt mac msdos pc98 sun loop; do done done +# loop filesystems support no flags. Make sure this doesn't crash + +if [ $ss == 512 ]; then + # only test on 512 byte ss since mke2fs assumes this on a file + truncate -s 5m img || framework_failure + mke2fs img || framework_failure + echo Error: No flags supported > out.exp + parted -s img set 1 foo on > out 2>&1 + compare out.exp out || fail=1 + parted -s img disk_set foo on > out 2>&1 + compare out.exp out || fail=1 +fi + Exit $fail -- 2.17.1