Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli_check_mydoom_log: Avoid unaligned access. #1293

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions libclamav/special.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

int cli_check_mydoom_log(cli_ctx *ctx)
{
const uint32_t *record;
uint32_t record[16];
const uint32_t *ptr;
uint32_t check, key;
fmap_t *map = ctx->fmap;
unsigned int blocks = map->len / (8 * 4);
Expand All @@ -59,14 +60,24 @@ int cli_check_mydoom_log(cli_ctx *ctx)
if (blocks > 5)
blocks = 5;

record = fmap_need_off_once(map, 0, 8 * 4 * blocks);
if (!record)
/*
* The following pointer might not be properly aligned. There there is
* memcmp() + memcpy() workaround to avoid performing an unaligned access
* while reading the uint32_t.
*/
ptr = fmap_need_off_once(map, 0, 8 * 4 * blocks);
if (!ptr)
return CL_CLEAN;

while (blocks) { /* This wasn't probably intended but that's what the current code does anyway */
if (record[--blocks] == 0xffffffff)
const uint32_t marker_ff = 0xffffffff;

if (!memcmp(&ptr[--blocks], &marker_ff, sizeof(uint32_t)))
return CL_CLEAN;
}

memcpy(record, ptr, sizeof(record));

key = ~be32_to_host(record[0]);
check = (be32_to_host(record[1]) ^ key) +
(be32_to_host(record[2]) ^ key) +
Expand Down
Loading