develooper Front page | perl.perl6.internals | Postings from May 2008

[perl #53714] [PATCH] parrot segfaults when dyna-loading main program

From:
Tom Erdevig
Date:
May 5, 2008 01:40
Subject:
[perl #53714] [PATCH] parrot segfaults when dyna-loading main program
# New Ticket Created by  Tom Erdevig 
# Please include the string:  [perl #53714]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=53714 >


Parrot segfaults running this:


.sub _ :main
    null S0
    loadlib P0, S0
.end


Invoking loadlib with null library-name argument should set P0
to a ParrotLibrary pmc handle on the currently running program.
This is useful for calling functions in the containing program
from an embedded parrot.

The segfault is caused by src/dynext.c:Parrot_load_lib setting
its local lib_name variable to NULL and then passing it along
to run_init_lib, and thence to store_lib_pmc, who tries to set
the new library PMC's '_lib_name' property using this NULL,
leading to the crash.

The attached patch fixes this in Parrot_load_lib by setting lib_name
to the empty string instead of NULL when there is no library name.
I'm not sure if that's the best choice.  The '_lib_name' library pmc
property doesn't seem to be used for anything elsewhere in parrot
(it gets copied if the library pmc gets cloned, but that's all).
The empty string is innocuous but not very helpful if a human should
happen to see it.  So perhaps setting the _lib_name to something like
"Not a library, this is the main program" would be better, but that
feels like overkill.


Change summary:

src/dynext.c  :  one-line fix as described
t/pmc/nci.t   :  add test that reproduces the problem and confirms fix


Diffstat:

 CREDITS      |    3 +++
 src/dynext.c |    2 +-
 t/pmc/nci.t  |   16 +++++++++++++++-
 3 files changed, 19 insertions(+), 2 deletions(-)


Tom




Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About