Browse Source

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 5 years ago
parent
commit
d44abe24f6
1 changed files with 12 additions and 12 deletions
  1. +12
    -12
      daemon/bencode.c

+ 12
- 12
daemon/bencode.c View File

@ -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) { 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)) if (len >= sizeof(*s))
return *s % BENCODE_HASH_BUCKETS; return *s % BENCODE_HASH_BUCKETS;


Loading…
Cancel
Save