mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Fix potential NULL pointer deref, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
3bb2eb2a8d
commit
b71605c819
1 file changed
+24
-4
+24
-4
@@ -80,7 +80,7 @@ static TAILQ_HEAD(, conf_change) conf_change_list = TAILQ_HEAD_INITIALIZER(conf_
|
|||||||
static int parse_conf(char *file, int is_rcsd);
|
static int parse_conf(char *file, int is_rcsd);
|
||||||
static void drop_changes(void);
|
static void drop_changes(void);
|
||||||
|
|
||||||
int get_bool(char *arg, int default_value)
|
static int get_bool(char *arg, int default_value)
|
||||||
{
|
{
|
||||||
if (!arg)
|
if (!arg)
|
||||||
goto fallback;
|
goto fallback;
|
||||||
@@ -93,6 +93,16 @@ fallback:
|
|||||||
return default_value;
|
return default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int validate_arg(char *arg, const char *opt)
|
||||||
|
{
|
||||||
|
if (!arg) {
|
||||||
|
errx(1, "option %s missing argument, skipping.", opt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* finit.cond = foo (=> <boot/foo>)
|
* finit.cond = foo (=> <boot/foo>)
|
||||||
* finit.config = /path/to/etc/alt-finit.conf
|
* finit.config = /path/to/etc/alt-finit.conf
|
||||||
@@ -110,11 +120,15 @@ static void parse_finit_opts(char *opt)
|
|||||||
*arg++ = 0;
|
*arg++ = 0;
|
||||||
|
|
||||||
if (string_compare(opt, "cond")) {
|
if (string_compare(opt, "cond")) {
|
||||||
|
if (validate_arg(arg, "finit.cond"))
|
||||||
|
return;
|
||||||
cond_boot_parse(arg);
|
cond_boot_parse(arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string_compare(opt, "config")) {
|
if (string_compare(opt, "config")) {
|
||||||
|
if (validate_arg(arg, "finit.config"))
|
||||||
|
return;
|
||||||
if (finit_conf)
|
if (finit_conf)
|
||||||
free(finit_conf);
|
free(finit_conf);
|
||||||
finit_conf = strdup(arg);
|
finit_conf = strdup(arg);
|
||||||
@@ -127,6 +141,8 @@ static void parse_finit_opts(char *opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string_compare(opt, "fstab")) {
|
if (string_compare(opt, "fstab")) {
|
||||||
|
if (validate_arg(arg, "finit.fstab"))
|
||||||
|
return;
|
||||||
if (fstab)
|
if (fstab)
|
||||||
free(fstab);
|
free(fstab);
|
||||||
fstab = strdup(arg);
|
fstab = strdup(arg);
|
||||||
@@ -134,10 +150,8 @@ static void parse_finit_opts(char *opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string_compare(opt, "status_style")) {
|
if (string_compare(opt, "status_style")) {
|
||||||
if (!arg) {
|
if (validate_arg(arg, "finit.status_style"))
|
||||||
errx(1, "status_style option requires an argument, skipping.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (string_compare(arg, "old") || string_compare(arg, "classic"))
|
if (string_compare(arg, "old") || string_compare(arg, "classic"))
|
||||||
show_progress(PROGRESS_CLASSIC);
|
show_progress(PROGRESS_CLASSIC);
|
||||||
@@ -161,6 +175,9 @@ static void parse_fsck_opts(char *opt)
|
|||||||
*arg++ = 0;
|
*arg++ = 0;
|
||||||
|
|
||||||
if (string_compare(opt, "mode")) {
|
if (string_compare(opt, "mode")) {
|
||||||
|
if (validate_arg(arg, "fsck.mode"))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!strcmp(arg, "skip"))
|
if (!strcmp(arg, "skip"))
|
||||||
fsck_mode = NULL;
|
fsck_mode = NULL;
|
||||||
if (!strcmp(arg, "auto"))
|
if (!strcmp(arg, "auto"))
|
||||||
@@ -172,6 +189,9 @@ static void parse_fsck_opts(char *opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string_compare(opt, "repair")) {
|
if (string_compare(opt, "repair")) {
|
||||||
|
if (validate_arg(arg, "fsck.repair"))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!strcmp(arg, "no"))
|
if (!strcmp(arg, "no"))
|
||||||
fsck_repair = "-n";
|
fsck_repair = "-n";
|
||||||
if (!strcmp(arg, "preen"))
|
if (!strcmp(arg, "preen"))
|
||||||
|
|||||||
Reference in new issue
Block a user