Skip to contentSkip to conversation

cpus: Fix botched configure_icount() error API violation fix

PATCH In review Markus Armbruster 3 participants 3 messages May 15, 2020 – May 21, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cpus: Fix botched configure_icount() error API violation fix

Before recent commit abc9bf69a66, configure_icount() returned early when option "shift" was absent: succeed when option "align" was also absent, else fail.

Since then, it still errors out when only "align" is present, but continues when both are absent. Crashes when examining the value of "shift" further. Reproducer: -icount "".

Revert this erroneous part of the commit.

Fixes abc9bf69a66a11499a801ff545b8fe7adbb3a04c
Fixes Coverity CID 1428754
---
 cpus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
cpus.c +4 -2
index 5670c96bcf..ee906dd08f 100644
@@ -803,8 +803,10 @@ void configure_icount(QemuOpts *opts, Error **errp)
     bool align = qemu_opt_get_bool(opts, "align", false);
     long time_shift = -1;
 
-    if (!option && qemu_opt_get(opts, "align")) {
-        error_setg(errp, "Please specify shift option when using align");
+    if (!option) {
+        if (qemu_opt_get(opts, "align") != NULL) {
+            error_setg(errp, "Please specify shift option when using align");
+        }
         return;
     }
 
Signature · 1 line
2.21.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 22 lines · Markus Armbruster

Before recent commit abc9bf69a66, configure_icount() returned early when option "shift" was absent: succeed when option "align" was also absent, else fail.

Since then, it still errors out when only "align" is present, but continues when both are absent. Crashes when examining the value of "shift" further. Reproducer: -icount "".

Revert this erroneous part of the commit.

Fixes abc9bf69a66a11499a801ff545b8fe7adbb3a04c
Fixes Coverity CID 1428754
---
  cpus.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
cpus.c +0 -0
index 5670c96bcf..ee906dd08f 100644

cpus.c void configure_icount(QemuOpts *opts, Error **errp) · line 807

Quoted 7 lines
cpus.c +2 -2
@@ -803,8 +803,10 @@ void configure_icount(QemuOpts *opts, Error **errp)
      bool align = qemu_opt_get_bool(opts, "align", false);
      long time_shift = -1;
 
-    if (!option && qemu_opt_get(opts, "align")) {
-        error_setg(errp, "Please specify shift option when using align");
+    if (!option) {
+        if (qemu_opt_get(opts, "align") != NULL) {
Quoted 6 lines
cpus.c +2 -0
+            error_setg(errp, "Please specify shift option when using align");
+        }
          return;
      }
 
#2 lore raw
In reply to Markus Armbruster
Quoted 25 lines · Markus Armbruster

Before recent commit abc9bf69a66, configure_icount() returned early when option "shift" was absent: succeed when option "align" was also absent, else fail.

Since then, it still errors out when only "align" is present, but continues when both are absent. Crashes when examining the value of "shift" further. Reproducer: -icount "".

Revert this erroneous part of the commit.

Fixes abc9bf69a66a11499a801ff545b8fe7adbb3a04c
Fixes Coverity CID 1428754
---
 cpus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
cpus.c +0 -0
index 5670c96bcf..ee906dd08f 100644
@@ -803,8 +803,10 @@ void configure_icount(QemuOpts *opts, Error **errp)
     bool align = qemu_opt_get_bool(opts, "align", false);
     long time_shift = -1;

cpus.c void configure_icount(QemuOpts *opts, Error **errp) · line 812

Quoted 10 lines
cpus.c +4 -2
 
-    if (!option && qemu_opt_get(opts, "align")) {
-        error_setg(errp, "Please specify shift option when using align");
+    if (!option) {
+        if (qemu_opt_get(opts, "align") != NULL) {
+            error_setg(errp, "Please specify shift option when using align");
+        }
         return;
     }
 

Got the nicer commit message, too.

Paolo