]>
Commit | Line | Data |
---|---|---|
74a816df MK |
1 | From 9e196cc2902255c328a90584e44666b79e4344c3 Mon Sep 17 00:00:00 2001 |
2 | From: Phillip Susi <psusi@ubuntu.com> | |
3 | Date: Thu, 10 May 2018 12:31:36 -0400 | |
4 | Subject: [PATCH 85/92] Fix set and disk_set to not crash when no flags are | |
5 | supported | |
6 | ||
7 | Loop labels and file images support no flags. set and disk_set | |
8 | would prompt for a flag and accept any string since the list of | |
9 | flags was empty, then fail to look up an actual flag value, then | |
10 | throw an exception with a null string for the name of the flag, | |
11 | which would bug. | |
12 | --- | |
13 | parted/ui.c | 18 ++++++++++++++++-- | |
14 | tests/t3310-flags.sh | 13 +++++++++++++ | |
15 | 3 files changed, 31 insertions(+), 2 deletions(-) | |
16 | ||
17 | diff --git a/parted/ui.c b/parted/ui.c | |
18 | index 752860b..4f42b7c 100644 | |
19 | --- a/parted/ui.c | |
20 | +++ b/parted/ui.c | |
21 | @@ -1132,7 +1132,14 @@ command_line_get_disk_flag (const char* | |
22 | opts = str_list_append_unique (opts, _(walk_name)); | |
23 | } | |
24 | } | |
25 | - | |
26 | + if (opts == NULL) | |
27 | + { | |
28 | + ped_exception_throw (PED_EXCEPTION_ERROR, | |
29 | + PED_EXCEPTION_OK, | |
30 | + _("No flags supported")); | |
31 | + | |
32 | + return 0; | |
33 | + } | |
34 | flag_name = command_line_get_word (prompt, NULL, opts, 1); | |
35 | str_list_destroy (opts); | |
36 | ||
37 | @@ -1161,7 +1168,14 @@ command_line_get_part_flag (const char* | |
38 | opts = str_list_append_unique (opts, _(walk_name)); | |
39 | } | |
40 | } | |
41 | - | |
42 | + if (opts == NULL) | |
43 | + { | |
44 | + ped_exception_throw (PED_EXCEPTION_ERROR, | |
45 | + PED_EXCEPTION_OK, | |
46 | + _("No flags supported")); | |
47 | + | |
48 | + return 0; | |
49 | + } | |
50 | flag_name = command_line_get_word (prompt, NULL, opts, 1); | |
51 | str_list_destroy (opts); | |
52 | ||
53 | diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh | |
54 | index 2da72d0..0997748 100644 | |
55 | --- a/tests/t3310-flags.sh | |
56 | +++ b/tests/t3310-flags.sh | |
57 | @@ -114,4 +114,17 @@ for table_type in aix amiga atari bsd dvh gpt mac msdos pc98 sun loop; do | |
58 | done | |
59 | done | |
60 | ||
61 | +# loop filesystems support no flags. Make sure this doesn't crash | |
62 | + | |
63 | +if [ $ss == 512 ]; then | |
64 | + # only test on 512 byte ss since mke2fs assumes this on a file | |
65 | + truncate -s 5m img || framework_failure | |
66 | + mke2fs img || framework_failure | |
67 | + echo Error: No flags supported > out.exp | |
68 | + parted -s img set 1 foo on > out 2>&1 | |
69 | + compare out.exp out || fail=1 | |
70 | + parted -s img disk_set foo on > out 2>&1 | |
71 | + compare out.exp out || fail=1 | |
72 | +fi | |
73 | + | |
74 | Exit $fail | |
75 | -- | |
76 | 2.17.1 | |
77 |