Patchwork ccid: Fix crash when backend isn't specified

login
register
mail settings
Submitter Cole Robinson
Date April 14, 2013, 8:06 p.m.
Message ID <681f15c0b6ac898724d68227f34977b106c7fa59.1365969853.git.crobinso@redhat.com>
Download mbox | patch
Permalink /patch/236469/
State New
Headers show

Comments

Cole Robinson - April 14, 2013, 8:06 p.m.
Reproducer:

./x86_64-softmmu/qemu-system-x86_64 -device usb-ccid,id=ccid0 -usb -device ccid-card-emulated -monitor stdio

Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
 hw/usb/ccid-card-emulated.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Alon Levy - April 15, 2013, 8:03 a.m.
On Sun, 2013-04-14 at 16:06 -0400, Cole Robinson wrote:
> Reproducer:
> 
> ./x86_64-softmmu/qemu-system-x86_64 -device usb-ccid,id=ccid0 -usb -device ccid-card-emulated -monitor stdio
> 

ACK, thanks.

Marc-Andre, could you review the fixed patches I sent previously, and
then I can put this on top and send a pull request?

http://lists.nongnu.org/archive/html/qemu-devel/2013-03/msg04927.html

> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
>  hw/usb/ccid-card-emulated.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
> index 29dcd7a..65e1432 100644
> --- a/hw/usb/ccid-card-emulated.c
> +++ b/hw/usb/ccid-card-emulated.c
> @@ -500,9 +500,15 @@ static int emulated_initfn(CCIDCardState *base)
>      if (init_pipe_signaling(card) < 0) {
>          return -1;
>      }
> -    card->backend = parse_enumeration(card->backend_str, backend_enum_table, 0);
> +
> +    card->backend = 0;
> +    if (card->backend_str) {
> +        card->backend = parse_enumeration(card->backend_str,
> +                                          backend_enum_table, 0);
> +    }
> +
>      if (card->backend == 0) {
> -        printf("unknown backend, must be one of:\n");
> +        printf("backend must be one of:\n");
>          for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) {
>              printf("%s\n", ptable->name);
>          }
> -- 
> 1.8.1.4
> 
>

Patch

diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index 29dcd7a..65e1432 100644
--- a/hw/usb/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -500,9 +500,15 @@  static int emulated_initfn(CCIDCardState *base)
     if (init_pipe_signaling(card) < 0) {
         return -1;
     }
-    card->backend = parse_enumeration(card->backend_str, backend_enum_table, 0);
+
+    card->backend = 0;
+    if (card->backend_str) {
+        card->backend = parse_enumeration(card->backend_str,
+                                          backend_enum_table, 0);
+    }
+
     if (card->backend == 0) {
-        printf("unknown backend, must be one of:\n");
+        printf("backend must be one of:\n");
         for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) {
             printf("%s\n", ptable->name);
         }