mirror of
https://github.com/troglobit/finit.git
synced 2026-11-27 20:48:24 +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;
|
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;
|
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;
|
return 0;
|
||||||
fallback:
|
fallback:
|
||||||
return default_value;
|
return default_value;
|
||||||
@@ -97,19 +97,24 @@ fallback:
|
|||||||
*/
|
*/
|
||||||
static void parse_finit_opts(char *opt)
|
static void parse_finit_opts(char *opt)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *arg;
|
||||||
|
|
||||||
ptr = strchr(opt, '=');
|
arg = strchr(opt, '=');
|
||||||
if (ptr)
|
if (arg)
|
||||||
*ptr++ = 0;
|
*arg++ = 0;
|
||||||
|
|
||||||
if (string_compare(opt, "debug")) {
|
if (string_compare(opt, "debug")) {
|
||||||
debug = get_bool(ptr, 1);
|
debug = get_bool(arg, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string_compare(opt, "status_style")) {
|
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);
|
show_progress(PROGRESS_CLASSIC);
|
||||||
else
|
else
|
||||||
show_progress(PROGRESS_MODERN);
|
show_progress(PROGRESS_MODERN);
|
||||||
@@ -117,7 +122,7 @@ static void parse_finit_opts(char *opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string_compare(opt, "show_status")) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user