From 053e00de97dca3fb9fd53ea2bf26f3edf20b4233 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Wed, 9 Dec 2020 16:17:22 +0000 Subject: [PATCH] warc: Fix undefined behaviour in deconst() function Creating a pointer by adding an offset to 0x1 is undefined behaviour and results in an invalid pointer when running on CHERI systems. Use a standards-compliant cast via uintptr_t instead. This was found due to a crash while running the libarchive test suite on a CHERI-RISC-V system. --- libarchive/archive_read_support_format_warc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libarchive/archive_read_support_format_warc.c b/libarchive/archive_read_support_format_warc.c index a582b81ad..27329962d 100644 --- a/libarchive/archive_read_support_format_warc.c +++ b/libarchive/archive_read_support_format_warc.c @@ -443,7 +443,7 @@ _warc_skip(struct archive_read *a) static void* deconst(const void *c) { - return (char *)0x1 + (((const char *)c) - (const char *)0x1); + return (void *)(uintptr_t)c; } static char* -- 2.47.2