diff mbox series

[v2,5/9] ccid-card-passthru: Replace assert() by QEMU_BUILD_BUG_ON()

Message ID 20190214201939.494-6-philmd@redhat.com
State New
Headers show
Series ccid-card-passthru: check buffer size parameter | expand

Commit Message

Philippe Mathieu-Daudé Feb. 14, 2019, 8:19 p.m. UTC
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/usb/ccid-card-passthru.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Marc-André Lureau Feb. 15, 2019, 11:44 a.m. UTC | #1
On Thu, Feb 14, 2019 at 9:20 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  hw/usb/ccid-card-passthru.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
> index ba7c285ded..ccc3ffa7fa 100644
> --- a/hw/usb/ccid-card-passthru.c
> +++ b/hw/usb/ccid-card-passthru.c
> @@ -29,6 +29,9 @@ do {                                                    \
>  #define D_MORE_INFO 3
>  #define D_VERBOSE 4
>
> +/* maximum size of ATR - from 7816-3 */
> +#define MAX_ATR_SIZE        40
> +
>  /* TODO: do we still need this? */
>  static const uint8_t DEFAULT_ATR[] = {
>  /*
> @@ -41,10 +44,9 @@ static const uint8_t DEFAULT_ATR[] = {
>   0x13, 0x08
>  };
>
> -#define VSCARD_IN_SIZE      (64 * KiB)
> +QEMU_BUILD_BUG_ON(sizeof(DEFAULT_ATR) > MAX_ATR_SIZE);
>
> -/* maximum size of ATR - from 7816-3 */
> -#define MAX_ATR_SIZE        40
> +#define VSCARD_IN_SIZE      (64 * KiB)
>
>  typedef struct PassthruState PassthruState;
>
> @@ -351,7 +353,6 @@ static void passthru_realize(CCIDCardState *base, Error **errp)
>      }
>      card->debug = parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE,
>                                    card->debug);
> -    assert(sizeof(DEFAULT_ATR) <= MAX_ATR_SIZE);
>      memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR));
>      card->atr_length = sizeof(DEFAULT_ATR);
>  }
> --
> 2.20.1
>
diff mbox series

Patch

diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index ba7c285ded..ccc3ffa7fa 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -29,6 +29,9 @@  do {                                                    \
 #define D_MORE_INFO 3
 #define D_VERBOSE 4
 
+/* maximum size of ATR - from 7816-3 */
+#define MAX_ATR_SIZE        40
+
 /* TODO: do we still need this? */
 static const uint8_t DEFAULT_ATR[] = {
 /*
@@ -41,10 +44,9 @@  static const uint8_t DEFAULT_ATR[] = {
  0x13, 0x08
 };
 
-#define VSCARD_IN_SIZE      (64 * KiB)
+QEMU_BUILD_BUG_ON(sizeof(DEFAULT_ATR) > MAX_ATR_SIZE);
 
-/* maximum size of ATR - from 7816-3 */
-#define MAX_ATR_SIZE        40
+#define VSCARD_IN_SIZE      (64 * KiB)
 
 typedef struct PassthruState PassthruState;
 
@@ -351,7 +353,6 @@  static void passthru_realize(CCIDCardState *base, Error **errp)
     }
     card->debug = parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE,
                                   card->debug);
-    assert(sizeof(DEFAULT_ATR) <= MAX_ATR_SIZE);
     memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR));
     card->atr_length = sizeof(DEFAULT_ATR);
 }