From 38ddc101ebcf864112f646026e149a6b0cc7f44a Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Tue, 26 Nov 2019 19:02:46 -0800 Subject: [PATCH] dev: avoid use of packed struct --- src/dev.c | 13 +++++++++++-- src/types.h | 5 ++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/dev.c b/src/dev.c index d0efac7..d24f707 100644 --- a/src/dev.c +++ b/src/dev.c @@ -102,19 +102,28 @@ fido_dev_open_tx(fido_dev_t *dev, const char *path) static int fido_dev_open_rx(fido_dev_t *dev, int ms) { + uint8_t data[17]; const uint8_t cmd = CTAP_FRAME_INIT | CTAP_CMD_INIT; int n; - if ((n = fido_rx(dev, cmd, &dev->attr, sizeof(dev->attr), ms)) < 0) { + if ((n = fido_rx(dev, cmd, data, sizeof(data), ms)) < 0) { fido_log_debug("%s: fido_rx", __func__); goto fail; } + memcpy(&dev->attr.nonce, &data[0], 8); + memcpy(&dev->attr.cid, &data[8], 4); + dev->attr.protocol = data[12]; + dev->attr.major = data[13]; + dev->attr.minor = data[14]; + dev->attr.build = data[15]; + dev->attr.flags = data[16]; + #ifdef FIDO_FUZZ dev->attr.nonce = dev->nonce; #endif - if ((size_t)n != sizeof(dev->attr) || dev->attr.nonce != dev->nonce) { + if ((size_t)n != sizeof(data) || dev->attr.nonce != dev->nonce) { fido_log_debug("%s: invalid nonce", __func__); goto fail; } diff --git a/src/types.h b/src/types.h index 42ed1b7..af72710 100644 --- a/src/types.h +++ b/src/types.h @@ -148,9 +148,8 @@ typedef struct fido_dev_info { char *product; /* product string */ } fido_dev_info_t; -PACKED_TYPE(fido_ctap_info_t, /* defined in section 8.1.9.1.3 (CTAPHID_INIT) of the fido2 ctap spec */ -struct fido_ctap_info { +typedef struct fido_ctap_info { uint64_t nonce; /* echoed nonce */ uint32_t cid; /* channel id */ uint8_t protocol; /* ctaphid protocol id */ @@ -158,7 +157,7 @@ struct fido_ctap_info { uint8_t minor; /* minor version number */ uint8_t build; /* build version number */ uint8_t flags; /* capabilities flags; see FIDO_CAP_* */ -}) +} fido_ctap_info_t; typedef struct fido_dev { uint64_t nonce; /* issued nonce */ -- 2.24.0