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

__FILE__ crash #3485

Closed
felixjones opened this issue Mar 6, 2017 · 1 comment
Closed

__FILE__ crash #3485

felixjones opened this issue Mar 6, 2017 · 1 comment

Comments

@felixjones
Copy link
Contributor

felixjones commented Mar 6, 2017

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__?

@felixjones
Copy link
Contributor Author

From inspection of

p->filename = "(null)";

It looks like the expected output should be "(null)", but this is failing at some point.

@matz matz closed this as completed in 63dbed0 Mar 7, 2017
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