summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-12-14 12:35:57 +0000
committerYves Orton <demerphq@gmail.com>2023-02-07 19:58:06 +0800
commit70bac31a4f4e90f39d9876a34715f0c83d2684dd (patch)
tree6782422bc597e3f7a5f660b0a7266cf12f4e3ff9 /util.c
parentaa2d00d7d06d0ec6110c4351b635728dfa53bc81 (diff)
downloadperl-70bac31a4f4e90f39d9876a34715f0c83d2684dd.tar.gz
Avoid a use-after-free warning by converting a pointer to a UV for debug print purposes before we call realloc() on it
Diffstat (limited to 'util.c')
-rw-r--r--util.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/util.c b/util.c
index 9a6ea72bca..9667e0f4a8 100644
--- a/util.c
+++ b/util.c
@@ -274,6 +274,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
#ifdef DEBUGGING
if ((SSize_t)size < 0)
Perl_croak_nocontext("panic: realloc, size=%" UVuf, (UV)size);
+ UV was_where = PTR2UV(where);
#endif
#ifdef PERL_DEBUG_READONLY_COW
if ((ptr = mmap(0, size, PROT_READ|PROT_WRITE,
@@ -326,7 +327,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
/* In particular, must do that fixup above before logging anything via
*printf(), as it can reallocate memory, which can cause SEGVs. */
- DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) rfree\n",PTR2UV(where),(long)PL_an++));
+ DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) rfree\n",was_where,(long)PL_an++));
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) realloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
if (ptr == NULL) {