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

Passing NULL to wrenInterpret for Module will crash. #631

Closed
IngwiePhoenix opened this issue Nov 11, 2018 · 0 comments
Closed

Passing NULL to wrenInterpret for Module will crash. #631

IngwiePhoenix opened this issue Nov 11, 2018 · 0 comments

Comments

@IngwiePhoenix
Copy link

I know, you shouldn't do that - but out of curiosity, I tried it... and, as expected, it wouldn't work, but instead crash the entire application. Here is what I did.

Ingwie@Ingwies-Macbook-Pro.local ~/W/G/w/out $ cat test.c
#include <stdio.h>
#include "wren.h"

void printOut(WrenVM* vm, const char* text) {
  printf("%s", text);
}

void printErr(
    WrenVM* vm, WrenErrorType type,
    const char* module, int line,
    const char* message
) {
  switch(type) {
    case WREN_ERROR_RUNTIME:
      printf("[wren] ERR: Runtime reported: \"%s\"\n", message);
      return;
    case WREN_ERROR_COMPILE:
      printf("[wren] ERR: (%s:%i) %s\n", module, line, message);
      return;
    case WREN_ERROR_STACK_TRACE:
      printf("[wren] STACK: %s:%i = %s", module, line, message);
      return;
  }
}

const char* rootCode =
"class A {\n"
"  construct new() { System.print('Constructed'); }\n"
"}\n";

const char* script =
"var a = A.new()";

int main(int argc, const char** argv) {
  WrenVM* vm;
  WrenConfiguration config;
  wrenInitConfiguration(&config);

  config.writeFn = printOut;
  config.errorFn = printErr;

  vm = wrenNewVM(&config);

  WrenInterpretResult rt;

  printf("Root: \n");
  rt = wrenInterpret(vm, NULL, rootCode);
  if(rt != WREN_RESULT_SUCCESS) exit(1);

  printf("Main: \n");
  rt = wrenInterpret(vm, "internal:main", script);
  if(rt != WREN_RESULT_SUCCESS) exit(1);

  wrenFreeVM(vm);
  exit(0);
}
Ingwie@Ingwies-Macbook-Pro.local ~/W/G/w/out $ gcc -I ../src/include/ ../lib/libwren.a test.c -o test
Ingwie@Ingwies-Macbook-Pro.local ~/W/G/w/out $ ./test
Root: 
fish: './test' terminated by signal SIGSEGV (Address boundary error)

Might want a sanity check if module is really not NULL?

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