Skip to content

Commit 7510b50

Browse files
committed
cli_check_mydoom_log: Avoid unaligned access.
fmap_need_off_once() may return an unaligned pointer. This in return leads to an unaligned access during the load of the uint32_t variables loading to failures on architectures not supporting unaligned access. This was reported to the Debian BTS as #1073128. [bigeasy: Commit message, reworked the patch a bit]. Link: https://bugs.debian.org/1073128 Patch-Name: cli_check_mydoom_log-Avoid-unaligned-access.patch Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
1 parent 1d30588 commit 7510b50

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

libclamav/special.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848

4949
int cli_check_mydoom_log(cli_ctx *ctx)
5050
{
51-
const uint32_t *record;
51+
const uint32_t record[16];
52+
const uint32_t *ptr;
5253
uint32_t check, key;
5354
fmap_t *map = ctx->fmap;
5455
unsigned int blocks = map->len / (8 * 4);
@@ -59,14 +60,25 @@ int cli_check_mydoom_log(cli_ctx *ctx)
5960
if (blocks > 5)
6061
blocks = 5;
6162

62-
record = fmap_need_off_once(map, 0, 8 * 4 * blocks);
63-
if (!record)
63+
/*
64+
* The following pointer might not be properly aligned. There there is
65+
* memcmp() + memcpy() workaround to avoid performing an unaligned access
66+
* while reading the uint32_t.
67+
*/
68+
ptr = fmap_need_off_once(map, 0, 8 * 4 * blocks);
69+
if (!ptr)
6470
return CL_CLEAN;
71+
6572
while (blocks) { /* This wasn't probably intended but that's what the current code does anyway */
66-
if (record[--blocks] == 0xffffffff)
73+
const uint32_t marker_ff = 0xffffffff;
74+
75+
blocks--;
76+
if (!memcmp(ptr + blocks, &marker_ff, sizeof(uint32_t)))
6777
return CL_CLEAN;
6878
}
6979

80+
memcpy(record, ptr, sizeof(record));
81+
7082
key = ~be32_to_host(record[0]);
7183
check = (be32_to_host(record[1]) ^ key) +
7284
(be32_to_host(record[2]) ^ key) +

0 commit comments

Comments
 (0)