Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update POD for Newx/Renew/Safefree vs libc analogs about heap corruption #22682

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

bulk88
Copy link
Contributor

@bulk88 bulk88 commented Oct 20, 2024

This isn't documented anywhere except in perlapi, in the per-macro/per-function section. A seasoned dev, will read perlguts ONCE, write code, then pass a Newx() pointer, to some 3rd party library or native OS API, and then instant disaster, or invisible disaster. If Newx() and libc malloc() pointers are interchangeable, on ONE particular OS, with ONE particular perl build, with ONE particular set of build flags, that is undefined behavior. Have fun with #define USE_MDH or -DUSE_MDH or -DDEBUGGING or #define MYMALLOC -DMYMALLOC.

Also, for anyone reading this in the future.

DO NOT EVER DOCUMENT the permutations where Newx() is libc malloc().

Perl core reserves the right, to separate Newx() and malloc(), at any time in a maint release if there are technical reasons to do so.

Also libperl.so/.dll embedders, if libperl is unloaded from the process, and deallocs all Newx() blocks globally, and a 3rd party library still loaded in the process, thinking it owns that "malloc()" block, that was given ownership of, in 3rd party lib API contract, SEGV time.


  • This set of changes requires a perldelta entry, and it is included.

pod/perldelta.pod Outdated Show resolved Hide resolved
@Leont
Copy link
Contributor

Leont commented Nov 28, 2024

Yeah, this is an interesting footgun that does deserve being document.

This isn't documented anywhere except in perlapi, in the
per-macro/per-function section. A seasoned dev, will read perlguts ONCE,
write code, then pass a Newx() pointer, to some 3rd party library or
native OS API, and then instant disaster, or invisible disaster. If
Newx() and libc malloc() pointers are interchangeable, on ONE particular
OS, with ONE particular perl build, with ONE particular set of build
flags, that is undefined behavior. Have fun with #define USE_MDH
or -DUSE_MDH or -DDEBUGGING or #define MYMALLOC -DMYMALLOC.

Also, for anyone reading this in the future.

DO NOT EVER DOCUMENT the permutations where Newx() is libc malloc().

Perl core reserves the right, to separate Newx() and malloc(), at any time
in a maint release if there are technical reasons to do so.

Also libperl.so/.dll embedders, if libperl is unloaded from the process,
and deallocs all Newx() blocks globally, and a 3rd party library still
loaded in the process, thinking it owns that "malloc()" block, that was
given ownership of, in 3rd party lib API contract, SEGV time.
@bulk88 bulk88 force-pushed the pod_PL_xs_c_mem_alloc branch from 94f01c2 to dbd48ea Compare December 19, 2024 08:54
@khwilliamson khwilliamson merged commit 1282565 into Perl:blead Dec 19, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants