vl: Fix an assert failure in error path
PATCH 1/1 vl: Fix an assert failure in error path
Based on the description of error_setg(), the local variable err in qemu_maybe_daemonize() should be initialized to NULL.
Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64: ../util/error.c:59: error_setv: Assertion `*errp == NULL' failed.
After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission denied
--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
softmmu/vl.c +1 -1
@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;os_daemonize ();rcu_disable_atfork ();
Signature · 1 line
2.25.1
Paolo Bonzini
AppliedQuoted 23 lines · Zhenzhong Duan
Based on the description of
error_setg(), the local variable err inqemu_maybe_daemonize()should be initialized to NULL.Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed.After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission deniedSigned-off-by Zhenzhong Duan <[email protected]>--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/vl.c +0
-0
softmmu/vl.c static void qemu_process_help_options(void) · line 2528
Quoted 8 lines
softmmu/vl.c +1
-1@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;os_daemonize ();rcu_disable_atfork ();
Queued, thanks.
Paolo
Quoted 14 lines · Paolo Bonzini
Quoted 13 lines · Zhenzhong Duan
Based on the description of
error_setg(), the local variable err inqemu_maybe_daemonize()should be initialized to NULL.
Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed. After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission deniedSigned-off-by Zhenzhong Duan <[email protected]>--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/vl.c +0
-0
Quoted 8 lines
softmmu/vl.c static void qemu_process_help_options(void) · line 2524
Quoted 8 lines
index
326c1e9080..feb4d201f3100644softmmu/vl.c +1
-1@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;
Common mistake, I'm afraid.
Quoted 5 lines
softmmu/vl.c static void qemu_process_help_options(void)
Quoted 3 lines
softmmu/vl.c +0
-0os_daemonize ();rcu_disable_atfork ();Queued, thanks.
Suggest to amend the commit message with
Fixes: 03d2b412aaf2078425f8472f31c8a9c2340969eb
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Zhenzhong Duan
Based on the description of
error_setg(), the local variable err inqemu_maybe_daemonize()should be initialized to NULL.
Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed. After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission deniedSigned-off-by Zhenzhong Duan <[email protected]>--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/vl.c +0
-1--- a/softmmu/vl.c
Quoted 8 lines
Quoted 6 lines
softmmu/vl.c static void qemu_process_help_options(void) · line 2524
Quoted 6 lines
+++
b/softmmu/vl.csoftmmu/vl.c +1
-1@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;Common mistake, I'm afraid.
Initializing isn't likely to be a performance impact, so I'd think we should make 'checkpatch.pl' complain about any 'Error *' variable that is not initialized to NULL, as a safety net, even if not technically required in some cases.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 28 lines · Daniel P. Berrangé
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Zhenzhong Duan
Based on the description of
error_setg(), the local variable err inqemu_maybe_daemonize()should be initialized to NULL.
Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed. After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission deniedSigned-off-by Zhenzhong Duan <[email protected]>--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/vl.c +0
-1--- a/softmmu/vl.cQuoted 8 lines
Quoted 6 lines
softmmu/vl.c static void qemu_process_help_options(void) · line 2524
Quoted 6 lines
+++
b/softmmu/vl.csoftmmu/vl.c +1
-1@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;Common mistake, I'm afraid.
Quoted 8 lines
Initializing isn't likely to be a performance impact, so I'd think we should make 'checkpatch.pl' complain about any 'Error *' variable that is not initialized to NULL, as a safety net, even if not technically required in some cases.
Regards,
Daniel
Hi,
Could we add a coccinelle script to check (and fix) these problems? e.g.:
@ r @
identifier id;
@@
Error *id
+ = NULL
;
Using this script, I found that local variable err in qemu_init_subsystems is not initialized to NULL too. The script is not prefect though, it will initialize all global/static 'Error *' variables and all local 'Error *' variables in util/error.c to NULL, which is unnecessary.
Thanks,
Peng
Quoted 34 lines · Peng Liang
Quoted 33 lines · Daniel P. Berrangé
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Zhenzhong Duan
Based on the description of
error_setg(), the local variable err inqemu_maybe_daemonize()should be initialized to NULL.
Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed. After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission deniedSigned-off-by Zhenzhong Duan <[email protected]>--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/vl.c +0
-1--- a/softmmu/vl.cQuoted 8 lines
Quoted 6 lines
softmmu/vl.c static void qemu_process_help_options(void) · line 2524
Quoted 6 lines
+++
b/softmmu/vl.csoftmmu/vl.c +1
-1@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;Common mistake, I'm afraid.
Initializing isn't likely to be a performance impact, so I'd think we should make 'checkpatch.pl' complain about any 'Error *' variable that is not initialized to NULL, as a safety net, even if not technically required in some cases.
Quoted 6 lines
Quoted 3 lines
Regards,
DanielHi,
Could we add a coccinelle script to check (and fix) these problems? e.g.:
Coccinelle is good for finding and fixing instances of bad patterns that have crept in. checkpatch is good for keeping them out. Both has its uses.
Quoted 9 lines
@ r @
identifier id;
@@
Error *id
+ = NULL
;Using this script, I found that local variable err in
qemu_init_subsystemsis not initialized to NULL too.
Crash bug, broken in commit efd7ab22fb "vl: extract qemu_init_subsystems", v6.0.0. Care to submit a fix?
Quoted 4 lines
The script is not
prefect though, it will initialize all global/static 'Error *' variables and all local 'Error *' variables inutil/error.cto NULL, which is unnecessary.
Excluding util/error.c is easy once you know how to:
@ depends on !(file in "util/error.c")@
identifier id;
@@
...Excluding variable definitions with static storage duraction shouldn't be too hard, either. If Coccinelle is sufficiently clever, adding keyword auto suffices. Else, try matching keyword static separately, like so:
(
static Error *id;
|
- Error *id;
+ Error *id = NULL;
)Completely untested.
Quoted 54 lines · Markus Armbruster
Quoted 34 lines · Peng Liang
Quoted 33 lines · Daniel P. Berrangé
Quoted 18 lines · Markus Armbruster
Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Zhenzhong Duan
Based on the description of
error_setg(), the local variable err inqemu_maybe_daemonize()should be initialized to NULL.
Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information.
Before the fix:
qemu-system-x86_64:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed. After fix:
qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission deniedSigned-off-by Zhenzhong Duan <[email protected]>--- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/vl.c +0
-1--- a/softmmu/vl.cQuoted 8 lines
Quoted 6 lines
softmmu/vl.c static void qemu_process_help_options(void) · line 2524
Quoted 6 lines
+++
b/softmmu/vl.csoftmmu/vl.c +1
-1@@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void)static void qemu_maybe_daemonize (const char *pid_file) { -Error *err; +Error *err =NULL ;Common mistake, I'm afraid.
Initializing isn't likely to be a performance impact, so I'd think we should make 'checkpatch.pl' complain about any 'Error *' variable that is not initialized to NULL, as a safety net, even if not technically required in some cases.
Quoted 6 lines
Quoted 3 lines
Regards,
DanielHi,
Could we add a coccinelle script to check (and fix) these problems? e.g.:Coccinelle is good for finding and fixing instances of bad patterns that have crept in. checkpatch is good for keeping them out. Both has its uses.
Quoted 7 lines
@ r @
identifier id;
@@
Error *id
+ = NULL
;
Quoted 5 lines
Quoted 2 lines
Using this script, I found that local variable err in
qemu_init_subsystemsis not initialized to NULL too.Crash bug, broken in commit
efd7ab22fb"vl: extractqemu_init_subsystems", v6.0.0. Care to submit a fix?
Have sent :)
Quoted 18 lines
Quoted 5 lines
The script is not
prefect though, it will initialize all global/static 'Error *' variables and all local 'Error *' variables inutil/error.cto NULL, which is unnecessary.Excluding
util/error.cis easy once you know how to:@ depends on !(file in "util/error.c")@ identifier id; @@ ...Excluding variable definitions with static storage duraction shouldn't be too hard, either. If Coccinelle is sufficiently clever, adding keyword auto suffices. Else, try matching keyword static separately, like so:
Quoted 9 lines
( static Error *id; | - Error *id; + Error *id = NULL; )Completely untested.
Thanks for your improvement!
Thanks,
Peng
Quoted 1 line · Markus Armbruster
Fixes 03d2b412aaf2078425f8472f31c8a9c2340969eb
Actually 0546c0609c ("vl: split various early command line options to a separate function", 2020-12-10).
Done, thanks!
Paolo