From: Paul Floyd Date: Sun, 7 Sep 2025 20:01:34 +0000 (+0200) Subject: Bug 509139 - Update BadSize error messages X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66f0174466cd0d97d1b123ac8152797fb34aeb8c;p=thirdparty%2Fvalgrind.git Bug 509139 - Update BadSize error messages --- diff --git a/NEWS b/NEWS index 7d087dfb6..85b7a17b1 100644 --- a/NEWS +++ b/NEWS @@ -96,6 +96,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 508958 FreeBSD: add getgroups and setgroups wrappers 509103 Fix tests/arm64/bug484935.c build with "-O2 -flto -ffat-lto-objects" 509107 memcheck/tests/duplicate_align_size_errors.cpp fails +509139 Update BadSize error messages To see details of a given bug, visit https://bugs.kde.org/show_bug.cgi?id=XXXXXX diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index d88f55f8b..0438fbdf0 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1073,6 +1073,8 @@ extern int * __error(void) __attribute__((weak)); #if defined(VGO_linux) + FREE_ALIGNED_SIZED(VG_Z_LIBC_SONAME, free_aligned_sized, free, FreeAlignedSized ); + FREE_ALIGNED_SIZED(SO_SYN_MALLOC, free_aligned_sized, free, FreeAlignedSized ); #elif defined(VGO_freebsd) FREE_ALIGNED_SIZED(VG_Z_LIBC_SONAME, free_aligned_sized, free, FreeAlignedSized ); diff --git a/memcheck/mc_errors.c b/memcheck/mc_errors.c index a708b3f85..657a11285 100644 --- a/memcheck/mc_errors.c +++ b/memcheck/mc_errors.c @@ -77,7 +77,7 @@ typedef Err_FishyValue, Err_ReallocSizeZero, Err_BadAlign, - Err_BadSize, + Err_UnsafeZeroSize, Err_SizeMismatch, Err_AlignMismatch, } @@ -177,9 +177,7 @@ struct _MC_Error { struct { AddrInfo ai; - SizeT size; - const HChar *func; - } BadSize; + } UnsafeZeroSize; // Call to strcpy, memcpy, etc, with overlapping blocks. struct { @@ -799,15 +797,13 @@ void MC_(pp_Error) ( const Error* err ) } break; - case Err_BadSize: + case Err_UnsafeZeroSize: if (xml) { emit( " InvalidSize\n" ); - emit( " %s invalid size value: %lu\n", - extra->Err.BadSize.func, extra->Err.BadSize.size ); + emit( " Unsafe allocation with size of zero is implementation-defined\n"); VG_(pp_ExeContext)( VG_(get_error_where)(err) ); } else { - emit( "%s invalid size value: %lu\n", - extra->Err.BadSize.func, extra->Err.BadSize.size ); + emit( "Unsafe allocation with size of zero is implementation-defined\n"); VG_(pp_ExeContext)( VG_(get_error_where)(err) ); } break; @@ -1028,13 +1024,10 @@ void MC_(record_bad_alignment) ( ThreadId tid, SizeT align, SizeT size, const HC VG_(maybe_record_error)( tid, Err_BadAlign, /*addr*/0, /*s*/NULL, &extra ); } -void MC_(record_bad_size) ( ThreadId tid, SizeT size, const HChar *function ) +void MC_(record_unsafe_zero_size) ( ThreadId tid ) { - MC_Error extra; tl_assert(VG_INVALID_THREADID != tid); - extra.Err.BadSize.size= size; - extra.Err.BadSize.func = function; - VG_(maybe_record_error)( tid, Err_BadSize, /*addr*/0, /*s*/NULL, &extra ); + VG_(maybe_record_error)( tid, Err_UnsafeZeroSize, /*addr*/0, /*s*/NULL, /*extra*/NULL ); } void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a ) @@ -1222,6 +1215,7 @@ Bool MC_(eq_Error) ( VgRes res, const Error* e1, const Error* e2 ) case Err_Overlap: case Err_Cond: case Err_ReallocSizeZero: + case Err_UnsafeZeroSize: return True; case Err_FishyValue: @@ -1253,11 +1247,6 @@ Bool MC_(eq_Error) ( VgRes res, const Error* e1, const Error* e2 ) extra2->Err.BadAlign.dealloc_align; } - case Err_BadSize: - // sized delete mismatch - return extra1->Err.BadSize.size == - extra2->Err.BadSize.size; - case Err_SizeMismatch: return extra1->Err.SizeMismatch.size == extra2->Err.SizeMismatch.size; @@ -1418,7 +1407,7 @@ UInt MC_(update_Error_extra)( const Error* err ) // we make it consistent with the others. case Err_Leak: case Err_BadAlign: - case Err_BadSize: + case Err_UnsafeZeroSize: case Err_SizeMismatch: case Err_AlignMismatch: return sizeof(MC_Error); @@ -1578,10 +1567,10 @@ typedef MempoolSupp, // Memory pool suppression. FishyValueSupp, // Fishy value suppression. ReallocSizeZeroSupp, // realloc size 0 suppression - BadAlignSupp, // Alignment not 2 - BadSizeSupp, // aligned alloc with size 0 - SizeMismatch, // Sized deallocation did not match allocation size - AlignMismatch, // Aligned deallocation did not match aligned allocation + BadAlignSupp, // Alignment not 2 + UnsafeZeroSizeSupp, // aligned alloc with size 0 + SizeMismatch, // Sized deallocation did not match allocation size + AlignMismatch, // Aligned deallocation did not match aligned allocation } MC_SuppKind; @@ -1614,7 +1603,7 @@ Bool MC_(is_recognised_suppression) ( const HChar* name, Supp* su ) else if (VG_STREQ(name, "FishyValue")) skind = FishyValueSupp; else if (VG_STREQ(name, "ReallocZero")) skind = ReallocSizeZeroSupp; else if (VG_STREQ(name, "BadAlign")) skind = BadAlignSupp; - else if (VG_STREQ(name, "BadSize")) skind = BadSizeSupp; + else if (VG_STREQ(name, "UnsafeZeroSize")) skind = UnsafeZeroSizeSupp; else if (VG_STREQ(name, "SizeMismatch")) skind = SizeMismatch; else if (VG_STREQ(name, "AlignMismatch")) skind = AlignMismatch; else @@ -1800,8 +1789,8 @@ Bool MC_(error_matches_suppression) ( const Error* err, const Supp* su ) case BadAlignSupp: return (ekind == Err_BadAlign); - case BadSizeSupp: - return (ekind == Err_BadSize); + case UnsafeZeroSizeSupp: + return (ekind == Err_UnsafeZeroSize); case SizeMismatch: return (ekind == Err_SizeMismatch); @@ -1835,7 +1824,7 @@ const HChar* MC_(get_error_name) ( const Error* err ) case Err_FishyValue: return "FishyValue"; case Err_ReallocSizeZero: return "ReallocZero"; case Err_BadAlign: return "BadAlign"; - case Err_BadSize: return "BadSize"; + case Err_UnsafeZeroSize: return "UnsafeZeroSize"; case Err_SizeMismatch: return "SizeMismatch"; case Err_AlignMismatch: return "AlignMismatch"; case Err_Addr: { diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index acc595a74..7cc5febe0 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -559,7 +559,7 @@ void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a ); void MC_(record_freemismatch_error) ( ThreadId tid, MC_Chunk* mc ); void MC_(record_realloc_size_zero) ( ThreadId tid, Addr a ); void MC_(record_bad_alignment) ( ThreadId tid, SizeT align, SizeT size, const HChar *msg); -void MC_(record_bad_size) ( ThreadId tid, SizeT align, const HChar *function); +void MC_(record_unsafe_zero_size) ( ThreadId tid); void MC_(record_overlap_error) ( ThreadId tid, const HChar* function, Addr src, Addr dst, SizeT szB ); diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c index 626d481d2..c7409156b 100644 --- a/memcheck/mc_main.c +++ b/memcheck/mc_main.c @@ -7231,7 +7231,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret ) } // size zero not allowed on all platforms (e.g. Illumos) if (aligned_alloc_info->size == 0) { - MC_(record_bad_size) ( tid, aligned_alloc_info->size, "memalign()" ); + MC_(record_unsafe_zero_size) ( tid ); } break; case AllocKindPosixMemalign: @@ -7243,7 +7243,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret ) MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , 0U, " (should be non-zero, a power of 2 and a multiple of sizeof(void*))" ); } if (aligned_alloc_info->size == 0) { - MC_(record_bad_size) ( tid, aligned_alloc_info->size, "posix_memalign()" ); + MC_(record_unsafe_zero_size) ( tid); } break; case AllocKindAlignedAlloc: @@ -7257,7 +7257,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret ) MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , aligned_alloc_info->size, " (size should be a multiple of alignment)" ); } if (aligned_alloc_info->size == 0) { - MC_(record_bad_size) ( tid, aligned_alloc_info->size, "aligned_alloc()" ); + MC_(record_unsafe_zero_size) ( tid ); } break; case AllocKindDeleteSized: @@ -7279,7 +7279,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret ) } break; case AllocKindFreeAlignedSized: - // same alignment checks as aligned_alloc + // same alignment checks as aligned_alloc, but allow a size of 0 if ((aligned_alloc_info->orig_alignment & (aligned_alloc_info->orig_alignment - 1)) != 0) { MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , 0U, " (should be a power of 2)" ); } @@ -7287,9 +7287,6 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret ) aligned_alloc_info->size % aligned_alloc_info->orig_alignment != 0U) { MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , aligned_alloc_info->size, " (size should be a multiple of alignment)" ); } - if (aligned_alloc_info->size == 0) { - MC_(record_bad_size) ( tid, aligned_alloc_info->size, "free_aligned_sized()" ); - } mc = VG_(HT_lookup) ( MC_(malloc_list), (UWord)aligned_alloc_info->mem ); if (mc && aligned_alloc_info->orig_alignment != mc->alignB) { MC_(record_align_mismatch_error) ( tid, mc, aligned_alloc_info->orig_alignment, False, "aligned_alloc/free_aligned_sized"); diff --git a/memcheck/tests/duplicate_align_size_errors.cpp b/memcheck/tests/duplicate_align_size_errors.cpp index 58f64a7cd..15c675958 100644 --- a/memcheck/tests/duplicate_align_size_errors.cpp +++ b/memcheck/tests/duplicate_align_size_errors.cpp @@ -29,7 +29,7 @@ int main() mem = nullptr; } - // Err.BadSize + // Err.UnsafeZeroSize mem = aligned_alloc(64U, 0U); if (mem) { diff --git a/memcheck/tests/duplicate_align_size_errors.stderr.exp b/memcheck/tests/duplicate_align_size_errors.stderr.exp index 4eb84f433..871c1c920 100644 --- a/memcheck/tests/duplicate_align_size_errors.stderr.exp +++ b/memcheck/tests/duplicate_align_size_errors.stderr.exp @@ -10,7 +10,7 @@ Invalid size value: 100 alignment value: 64 (size should be a multiple of alignm at 0x........: aligned_alloc (vg_replace_malloc.c:...) by 0x........: main (duplicate_align_size_errors.cpp:25) -aligned_alloc() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: aligned_alloc (vg_replace_malloc.c:...) by 0x........: main (duplicate_align_size_errors.cpp:33) diff --git a/memcheck/tests/duplicate_align_size_errors.stderr.exp-memalign b/memcheck/tests/duplicate_align_size_errors.stderr.exp-memalign index 250b05070..16ecf7714 100644 --- a/memcheck/tests/duplicate_align_size_errors.stderr.exp-memalign +++ b/memcheck/tests/duplicate_align_size_errors.stderr.exp-memalign @@ -6,7 +6,7 @@ Invalid alignment value: 0 (should be non-zero and a power of 2) at 0x........: operator delete(void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) by 0x........: main (duplicate_align_size_errors.cpp:20) -memalign() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (duplicate_align_size_errors.cpp:33) diff --git a/memcheck/tests/freebsd/aligned_allocs_supp.supp b/memcheck/tests/freebsd/aligned_allocs_supp.supp index 56676481e..122766f9c 100644 --- a/memcheck/tests/freebsd/aligned_allocs_supp.supp +++ b/memcheck/tests/freebsd/aligned_allocs_supp.supp @@ -14,7 +14,7 @@ { aligned_alloc bad size - Memcheck:BadSize + Memcheck:UnsafeZeroSize fun:aligned_alloc fun:main } diff --git a/memcheck/tests/freebsd/errno_aligned_allocs.stderr.exp b/memcheck/tests/freebsd/errno_aligned_allocs.stderr.exp index c555d9bdd..93c66c70b 100644 --- a/memcheck/tests/freebsd/errno_aligned_allocs.stderr.exp +++ b/memcheck/tests/freebsd/errno_aligned_allocs.stderr.exp @@ -11,7 +11,7 @@ Invalid alignment value: 40 (should be non-zero, a power of 2 and a multiple of at 0x........: posix_memalign (vg_replace_malloc.c:...) by 0x........: main (errno_aligned_allocs.c:20) -aligned_alloc() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: aligned_alloc (vg_replace_malloc.c:...) by 0x........: main (errno_aligned_allocs.c:60) diff --git a/memcheck/tests/linux/memalign.stderr.exp b/memcheck/tests/linux/memalign.stderr.exp index ae9dc6e35..630af58f1 100644 --- a/memcheck/tests/linux/memalign.stderr.exp +++ b/memcheck/tests/linux/memalign.stderr.exp @@ -34,7 +34,7 @@ Invalid alignment value: 4097 (should be power of 2) at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (memalign.c:78) -memalign() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (memalign.c:87) diff --git a/memcheck/tests/linux/memalign.stderr.exp-musl b/memcheck/tests/linux/memalign.stderr.exp-musl index 6d3d3ac98..61e9177e8 100644 --- a/memcheck/tests/linux/memalign.stderr.exp-musl +++ b/memcheck/tests/linux/memalign.stderr.exp-musl @@ -34,7 +34,7 @@ Invalid alignment value: 4097 (should be power of 2) at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (memalign.c:145) -memalign() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (memalign.c:155) diff --git a/memcheck/tests/posix_memalign.stderr.exp b/memcheck/tests/posix_memalign.stderr.exp index 3f8075f63..1c4701370 100644 --- a/memcheck/tests/posix_memalign.stderr.exp +++ b/memcheck/tests/posix_memalign.stderr.exp @@ -1,4 +1,4 @@ -posix_memalign() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: posix_memalign (vg_replace_malloc.c:...) by 0x........: main (posix_memalign.c:32) diff --git a/memcheck/tests/posix_memalign_supp.supp b/memcheck/tests/posix_memalign_supp.supp index a38ba23b0..23572e40f 100644 --- a/memcheck/tests/posix_memalign_supp.supp +++ b/memcheck/tests/posix_memalign_supp.supp @@ -1,7 +1,7 @@ { posix_memalign size - Memcheck:BadSize + Memcheck:UnsafeZeroSize fun:posix_memalign fun:main } @@ -15,8 +15,8 @@ # Darwin uses zones { - posix_memalign size - Memcheck:BadSize + posix_memalign zero size + Memcheck:UnsafeZeroSize fun:malloc_zone_memalign fun:posix_memalign fun:main diff --git a/memcheck/tests/posix_memalign_xml.stderr.exp b/memcheck/tests/posix_memalign_xml.stderr.exp index ce9ded320..9941ebc66 100644 --- a/memcheck/tests/posix_memalign_xml.stderr.exp +++ b/memcheck/tests/posix_memalign_xml.stderr.exp @@ -32,7 +32,7 @@ 0x........ ... InvalidSize - posix_memalign() invalid size value: 0 + Unsafe allocation with size of zero is implementation-defined 0x........ diff --git a/memcheck/tests/solaris/memalign.stderr.exp b/memcheck/tests/solaris/memalign.stderr.exp index dd2441252..fa9e333a5 100644 --- a/memcheck/tests/solaris/memalign.stderr.exp +++ b/memcheck/tests/solaris/memalign.stderr.exp @@ -1,4 +1,4 @@ -memalign() invalid size value: 0 +Unsafe allocation with size of zero is implementation-defined at 0x........: memalign (vg_replace_malloc.c:...) by 0x........: main (memalign.c:29)