From: Alex Richardson Date: Wed, 9 Dec 2020 16:17:22 +0000 (+0000) Subject: warc: Fix undefined behaviour in deconst() function X-Git-Tag: v3.5.1~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1465%2Fhead;p=thirdparty%2Flibarchive.git 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. --- 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*