From: Michael Gilbert Date: Wed, 6 Jul 2022 00:44:32 +0000 (+0100) Subject: fix incomplete memory wrap around logic (gcc 12 -Waddress) X-Git-Tag: archive/raspbian/7.0_repack-10+rpi1~3^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5ccee41c5d24afcfbded3439cb2f7e2b37c28a16;p=wine.git fix incomplete memory wrap around logic (gcc 12 -Waddress) Gbp-Pq: Topic warnings Gbp-Pq: Name address.patch --- diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 1f817cd..0ed89b6 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -235,10 +236,13 @@ void *anon_mmap_alloc( size_t size, int prot ) static void mmap_add_reserved_area( void *addr, SIZE_T size ) { + SIZE_T max_size = SIZE_MAX - (SIZE_T)addr; struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + _Static_assert(sizeof(SIZE_MAX) == sizeof(SIZE_T), "SIZE_MAX and SIZE_T are not the same size"); + + if (size > max_size) size = max_size; /* avoid wrap-around */ LIST_FOR_EACH( ptr, &reserved_areas ) { @@ -284,10 +288,13 @@ static void mmap_add_reserved_area( void *addr, SIZE_T size ) static void mmap_remove_reserved_area( void *addr, SIZE_T size ) { + SIZE_T max_size = SIZE_MAX - (SIZE_T)addr; struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + _Static_assert(sizeof(SIZE_MAX) == sizeof(SIZE_T), "SIZE_MAX and SIZE_T are not the same size"); + + if (size > max_size) size = max_size; /* avoid wrap-around */ ptr = list_head( &reserved_areas ); /* find the first area covering address */ diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c index ad51153..c8b6bba 100644 --- a/libs/wine/mmap.c +++ b/libs/wine/mmap.c @@ -498,10 +498,13 @@ void mmap_init(void) */ void wine_mmap_add_reserved_area_obsolete( void *addr, size_t size ) { + size_t max_size = SIZE_MAX - (size_t)addr; struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + _Static_assert(sizeof(SIZE_MAX) == sizeof(size_t), "SIZE_MAX and SIZE_T are not the same size"); + + if (size > max_size) size = max_size; /* avoid wrap-around */ LIST_FOR_EACH( ptr, &reserved_areas ) { @@ -557,10 +560,13 @@ void wine_mmap_add_reserved_area_obsolete( void *addr, size_t size ) */ void wine_mmap_remove_reserved_area_obsolete( void *addr, size_t size, int unmap ) { + size_t max_size = SIZE_MAX - (size_t)addr; struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + _Static_assert(sizeof(SIZE_MAX) == sizeof(size_t), "SIZE_MAX and SIZE_T are not the same size"); + + if (size > max_size) size = max_size; /* avoid wrap-around */ ptr = list_head( &reserved_areas ); /* find the first area covering address */