summaryrefslogtreecommitdiff
path: root/libusb/descriptor.c
diff options
context:
space:
mode:
authorSaleem Rashid <dev@saleemrashid.com>2020-05-21 18:12:04 +0100
committerChris Dickens <christopher.a.dickens@gmail.com>2020-08-10 10:45:09 -0700
commitf492968d953f233e6b6946afd402f6718ff7a500 (patch)
treede634a94f8b26a4e7643c62222085e3806acdd7b /libusb/descriptor.c
parent4261cbefc716e49d459426593cef0104482ec43b (diff)
downloadlibusb-f492968d953f233e6b6946afd402f6718ff7a500.tar.gz
descriptor: Fix alignment for 32-bit words in parse_descriptor
parse_descriptor was aligning 32-bit words to 2 bytes, instead of 4 bytes. This didn't cause any issues before, because the only time the 32-bit word code path is used is from a 3 byte offset (which incidentally aligns to 4 bytes). However, a 1 byte offset would incorrectly align to 2 bytes. Closes #734 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/descriptor.c')
-rw-r--r--libusb/descriptor.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 2097b84..be0aa83 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -53,14 +53,14 @@ static void parse_descriptor(const void *source, const char *descriptor, void *d
*dp++ = *sp++;
break;
case 'w': /* 16-bit word, convert from little endian to CPU */
- dp += ((uintptr_t)dp & 1); /* Align to word boundary */
+ dp += ((uintptr_t)dp & 1); /* Align to word boundary */
*((uint16_t *)dp) = READ_LE16(sp);
sp += 2;
dp += 2;
break;
case 'd': /* 32-bit word, convert from little endian to CPU */
- dp += ((uintptr_t)dp & 1); /* Align to word boundary */
+ dp = (uint8_t *)(((uintptr_t)dp + 3) & ~3); /* Align to word boundary */
*((uint32_t *)dp) = READ_LE32(sp);
sp += 4;