summaryrefslogtreecommitdiff
path: root/pkg/libfido2/patch/0005-dev-avoid-use-of-packed-struct.patch
blob: c31e64db0ce40d000d3dbc17f5a245907f880a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 38ddc101ebcf864112f646026e149a6b0cc7f44a Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
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