[PATCH v2] cpus: Fix botched configure_icount() error API violation fix

Markus Armbruster posted 1 patch 3 years, 11 months ago
Test docker-mingw@fedora passed
Test checkpatch passed
Test asan passed
Test docker-quick@centos7 passed
Test FreeBSD passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200515042231.18201-1-armbru@redhat.com
Maintainers: Richard Henderson <rth@twiddle.net>, Paolo Bonzini <pbonzini@redhat.com>
cpus.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH v2] cpus: Fix botched configure_icount() error API violation fix
Posted by Markus Armbruster 3 years, 11 months ago
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
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 cpus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 5670c96bcf..ee906dd08f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -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;
     }
 
-- 
2.21.1


Re: [PATCH v2] cpus: Fix botched configure_icount() error API violation fix
Posted by Philippe Mathieu-Daudé 3 years, 11 months ago
On 5/15/20 6:22 AM, Markus Armbruster wrote:
> 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
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   cpus.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 5670c96bcf..ee906dd08f 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -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) {

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +            error_setg(errp, "Please specify shift option when using align");
> +        }
>           return;
>       }
>   
> 


Re: [PATCH v2] cpus: Fix botched configure_icount() error API violation fix
Posted by Paolo Bonzini 3 years, 11 months ago
On 15/05/20 06:22, Markus Armbruster wrote:
> 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
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  cpus.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 5670c96bcf..ee906dd08f 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -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;
>      }
>  
> 

Got the nicer commit message, too.

Paolo