Lock unsafe command-line options after enabling GUI mode
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-09-16 12:35:32 +02:00
parent 209b902301
commit a11ebd8ad3
3 changed files with 52 additions and 3 deletions

View file

@ -207,6 +207,7 @@ void log_close(const char* file)
/**
* Test options
*/
#define OPT_TEST_FIRST 256
#define OPT_TEST_SKIP_SELF 256
#define OPT_TEST_KILL_AFTER_SYNC 257
#define OPT_TEST_EXPECT_UNRECOVERABLE 258
@ -257,6 +258,7 @@ void log_close(const char* file)
#define OPT_TEST_SPEED_BLOCKS_SIZE 309
#define OPT_TEST_KILL_BEFORE_SYNC 310
#define OPT_TEST_KILL_AFTER_RESIZE 311
#define OPT_TEST_LAST 311
#if HAVE_GETOPT_LONG
static struct option long_options[] = {
@ -458,6 +460,24 @@ static struct option long_options[] = {
*/
#define OPTIONS "t:c:f:d:mebp:o:S:B:L:i:l:AZEUDNFRW:ahTC:vqHVw:"
static int option_gui_locked(int c)
{
if (c >= OPT_TEST_FIRST && c <= OPT_TEST_LAST)
return 1;
switch (c) {
case 'c' : /* --conf */
case 'C' : /* --gen-conf */
case 'l' : /* --log */
case 'H' : /* --help */
case 'V' : /* --version */
case 'T' : /* --speed-test */
return 1;
}
return 0;
}
static int parse_option_size(const char* arg, uint64_t* out_size)
{
char* e;
@ -544,6 +564,7 @@ int snapraid_main(int argc, char* argv[])
const char* import_content;
const char* log_file;
int lock;
int gui_locked;
const char* gen_conf;
#if HAVE_CHECKER
const char* run;
@ -584,6 +605,7 @@ int snapraid_main(int argc, char* argv[])
import_content = 0;
log_file = 0;
lock = 0;
gui_locked = 0;
gen_conf = 0;
speedtest = 0;
#if HAVE_CHECKER
@ -598,6 +620,11 @@ int snapraid_main(int argc, char* argv[])
getopt(argc, argv, OPTIONS))
#endif
!= EOF) {
if (gui_locked && option_gui_locked(c)) {
log_fatal(EUSER, "Option not allowed after --gui.\n");
exit(EXIT_FAILURE);
}
switch (c) {
case 'c' :
pathimport(conf, sizeof(conf), optarg);
@ -807,9 +834,11 @@ int snapraid_main(int argc, char* argv[])
break;
case OPT_GUI :
opt.gui = 1;
gui_locked = 1;
break;
case OPT_GUI_VERBOSE :
opt.gui = 1;
gui_locked = 1;
opt.gui_verbose = 1;
break;
case OPT_GUI_RESCAN_AFTER :