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

SIGABRT when reading nonexistent array members #30

Open
FGasper opened this issue Nov 17, 2021 · 0 comments
Open

SIGABRT when reading nonexistent array members #30

FGasper opened this issue Nov 17, 2021 · 0 comments

Comments

@FGasper
Copy link
Contributor

FGasper commented Nov 17, 2021

#!perl

use strict;
use warnings;

use FindBin;
use blib;

use JavaScript::Duktape::XS;

my $js = JavaScript::Duktape::XS->new();

$js->eval(
    qq<
        var croaker = function() { throw "hahaha" };
        var got = [];
        try {
            croaker();
        }
        catch(e) {
            got[1] = e;
        }

        got
    >
);

… yields SIGABRT, with the following output:

duktape fatal error, aborting: uncaught: 'cannot read property 1 of undefined'
FGasper added a commit to FGasper/JavaScript-Duktape-XS that referenced this issue Nov 17, 2021
Issue gonzus#30: JS “undefined” causes Duktape’s duk_get_prop_index()
to return false, even though the value *does* exist. (This is an
apparent bug either in Duktape or its documentation, which suggests
that any existent property should cause a truthy return from that
function.) In that case pl_duk_to_perl_impl() was neglecting to
duk_pop(ctx), which caused the next read on the array to be an attempt
to read index 1 from undefined, which triggered an abort().

This fixes that by ensuring that we always duk_pop(ctx) in the relevant
piece of code.
FGasper added a commit to FGasper/JavaScript-Duktape-XS that referenced this issue Nov 17, 2021
Issue gonzus#30: JS “undefined” causes Duktape’s duk_get_prop_index()
to return false, even though the value *does* exist. (This is an
apparent bug either in Duktape or its documentation, which suggests
that any existent property should cause a truthy return from that
function.) In that case pl_duk_to_perl_impl() was neglecting to
duk_pop(ctx), which caused the next read on the array to be an attempt
to read index 1 from undefined, which triggered an abort().

This fixes that by ensuring that we always duk_pop(ctx) in the relevant
piece of code.
FGasper added a commit to FGasper/JavaScript-Duktape-XS that referenced this issue Nov 17, 2021
Issue gonzus#30: JS “undefined” causes Duktape’s duk_get_prop_index()
to return false, even though the value *does* exist. (This is an
apparent bug either in Duktape or its documentation, which suggests
that any existent property should cause a truthy return from that
function.) In that case pl_duk_to_perl_impl() was neglecting to
duk_pop(ctx), which caused the next read on the array to be an attempt
to read index 1 from undefined, which triggered an abort().

This fixes that by ensuring that we always duk_pop(ctx) in the relevant
piece of code.
@FGasper FGasper changed the title SIGABRT on try/catch SIGABRT when reading nonexistent array members Nov 17, 2021
FGasper added a commit to FGasper/JavaScript-Duktape-XS that referenced this issue Dec 3, 2021
Issue gonzus#30: Missing JS array items cause Duktape’s duk_get_prop_index()
to return false. In that case pl_duk_to_perl_impl() was neglecting to
duk_pop(ctx), which caused the next read on the array to be an attempt
to read index 1 from undefined, which triggered an abort().

This fixes that by ensuring that we always duk_pop(ctx) in the relevant
piece of code and return Perl undef to represent missing array items.
FGasper added a commit to FGasper/JavaScript-Duktape-XS that referenced this issue Dec 3, 2021
Issue gonzus#30: Missing JS array items cause Duktape’s duk_get_prop_index()
to return false. In that case pl_duk_to_perl_impl() was neglecting to
duk_pop(ctx), which caused the next read on the array to be an attempt
to read index 1 from undefined, which triggered an abort().

This fixes that by ensuring that we always duk_pop(ctx) in the relevant
piece of code and return Perl undef to represent missing array items.
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

No branches or pull requests

1 participant