Skip to content

__FILE__ crash #3485

@felixjones

Description

@felixjones

Following causes a crash:

mrb_state * mrb = mrb_open();
mrb_load_string( mrb, "__FILE__" );

enable_debug prints:

mrb_debug_info_append_file: assertion "irep->filename" failed

The culprit is the strlen check here:
https://github.com/mruby/mruby/blob/master/src/debug.c#L157

It is my understanding that strlen( NULL ) is undefined behaviour. I expect there are platforms that will return 0 for this case and thus silently continue.

Removing the assert and changing 157 to check for NULL fixes the crash:

// mrb_assert(irep->filename);
fn_len = irep->filename ? strlen(irep->filename) : 0;

I don't consider this a solution as it results in __FILE__ printing as (null), rather than anything meaningful.

In the case of __FILE__ without a file-name, what is the expected output? Is there a mechanism for defining the value for __FILE__?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions