mirror of
https://github.com/troglobit/finit.git
synced 2026-10-16 10:39:35 +00:00
Fix possible NULL ptr deref in cmdline option parser
Found by Coverity Scan. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
1434561a46
commit
9d949c4186
1 file changed
+16
-11
+16
-11
@@ -78,14 +78,14 @@ static void hide_args(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
int get_bool(char *ptr, int default_value)
|
||||
int get_bool(char *arg, int default_value)
|
||||
{
|
||||
if (!ptr)
|
||||
if (!arg)
|
||||
goto fallback;
|
||||
|
||||
if (string_compare(ptr, "true") || string_compare(ptr, "on") || string_compare(ptr, "1"))
|
||||
if (string_compare(arg, "true") || string_compare(arg, "on") || string_compare(arg, "1"))
|
||||
return 1;
|
||||
if (string_compare(ptr, "false") || string_compare(ptr, "off") || string_compare(ptr, "0"))
|
||||
if (string_compare(arg, "false") || string_compare(arg, "off") || string_compare(arg, "0"))
|
||||
return 0;
|
||||
fallback:
|
||||
return default_value;
|
||||
@@ -97,19 +97,24 @@ fallback:
|
||||
*/
|
||||
static void parse_finit_opts(char *opt)
|
||||
{
|
||||
char *ptr;
|
||||
char *arg;
|
||||
|
||||
ptr = strchr(opt, '=');
|
||||
if (ptr)
|
||||
*ptr++ = 0;
|
||||
arg = strchr(opt, '=');
|
||||
if (arg)
|
||||
*arg++ = 0;
|
||||
|
||||
if (string_compare(opt, "debug")) {
|
||||
debug = get_bool(ptr, 1);
|
||||
debug = get_bool(arg, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string_compare(opt, "status_style")) {
|
||||
if (string_compare(ptr, "old") || string_compare(ptr, "classic"))
|
||||
if (!arg) {
|
||||
_e("status_style option requires an argument, skipping.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string_compare(arg, "old") || string_compare(arg, "classic"))
|
||||
show_progress(PROGRESS_CLASSIC);
|
||||
else
|
||||
show_progress(PROGRESS_MODERN);
|
||||
@@ -117,7 +122,7 @@ static void parse_finit_opts(char *opt)
|
||||
}
|
||||
|
||||
if (string_compare(opt, "show_status")) {
|
||||
show_progress(get_bool(ptr, 1) ? PROGRESS_DEFAULT : PROGRESS_SILENT);
|
||||
show_progress(get_bool(arg, 1) ? PROGRESS_DEFAULT : PROGRESS_SILENT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user