TT#111150 fix possible unaligned memory access

Avoid accessing memory via pointers that may not be aligned, which is
undefined behaviour on some archs. Use memcpy for this purpose instead.

Change-Id: Iec6c8d15fdd7ef00896e494b69412847b637b01b
pull/1285/head
Richard Fuchs 4 years ago
parent ef5a954e4c
commit d44abe24f6

@ -406,21 +406,21 @@ char *bencode_collapse_dup(bencode_item_t *root, int *len) {
}
static unsigned int __bencode_hash_str_len(const unsigned char *s, int len) {
unsigned long *ul;
unsigned int *ui;
unsigned short *us;
unsigned long ul;
unsigned int ui;
unsigned short us;
if (len >= sizeof(*ul)) {
ul = (void *) s;
return *ul % BENCODE_HASH_BUCKETS;
if (len >= sizeof(ul)) {
memcpy(&ul, s, sizeof(ul));
return ul % BENCODE_HASH_BUCKETS;
}
if (len >= sizeof(*ui)) {
ui = (void *) s;
return *ui % BENCODE_HASH_BUCKETS;
if (len >= sizeof(ui)) {
memcpy(&ui, s, sizeof(ui));
return ui % BENCODE_HASH_BUCKETS;
}
if (len >= sizeof(*us)) {
us = (void *) s;
return *us % BENCODE_HASH_BUCKETS;
if (len >= sizeof(us)) {
memcpy(&us, s, sizeof(us));
return us % BENCODE_HASH_BUCKETS;
}
if (len >= sizeof(*s))
return *s % BENCODE_HASH_BUCKETS;

Loading…
Cancel
Save