Skip to content

Commit

Permalink
[LibOS] Fix pointer alignment issue in __hash()
Browse files Browse the repository at this point in the history
The issue was found by UBSAN.
  • Loading branch information
stefanberger authored and mkow committed Jan 19, 2021
1 parent b534b45 commit eb3c58f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion LibOS/shim/src/fs/shim_fs_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

static HASHTYPE __hash(const char* p, size_t len) {
HASHTYPE hash = 0;
HASHTYPE tmp;

for (; len >= sizeof(hash); p += sizeof(hash), len -= sizeof(hash)) {
hash += *((HASHTYPE*)p);
memcpy(&tmp, p, sizeof(tmp)); /* avoid pointer alignment issues */
hash += tmp;
hash *= 9;
}

Expand Down

0 comments on commit eb3c58f

Please sign in to comment.