[parted-devel] [PATCH] Fix set and disk_set to not crash when no flags are supported

Phillip Susi psusi at ubuntu.com
Thu May 10 18:00:56 BST 2018


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.
---
 NEWS                 |  2 ++
 parted/ui.c          | 18 ++++++++++++++++--
 tests/t3310-flags.sh | 13 +++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 9fe2033..d419e76 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug Fixes
 
+  Fix set and disk_set to not crash when there are no flags to set.
+
   Fix resizepart to discard changes after getting the warning about
   shirnking a partition and answering No.
 
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.7.4




More information about the parted-devel mailing list