Skip to content

Commit d33798d

Browse files
fix: null pointer deref in FRAME_BUILTIN_FORCE_THUNKS impl
Since #1299 there is a code-path which constructs a `FRAME_BUILTIN_FORCE_THUNKS` Frame with `nullptr` `ast`. Somehow this did not cause crashes in the test suite (until it was run with a more hardened build)
1 parent 6a035d9 commit d33798d

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

core/vm.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,11 +2798,11 @@ class Interpreter {
27982798
} break;
27992799

28002800
case FRAME_BUILTIN_FORCE_THUNKS: {
2801-
const auto &ast = *static_cast<const Apply *>(f.ast);
2801+
const auto &location = f.location;
28022802
auto *func = static_cast<HeapClosure *>(f.val.v.h);
28032803
if (f.elementId == f.thunks.size()) {
28042804
// All thunks forced, now the builtin implementations.
2805-
const LocationRange &loc = ast.location;
2805+
const LocationRange &loc = location;
28062806
const std::string &builtin_name = func->builtinName;
28072807
std::vector<Value> args;
28082808
for (const auto &p : func->params) {
@@ -2855,7 +2855,7 @@ class Interpreter {
28552855
break;
28562856

28572857
default:
2858-
throw makeError(ast.location,
2858+
throw makeError(location,
28592859
"native extensions can only take primitives.");
28602860
}
28612861
}
@@ -2864,7 +2864,7 @@ class Interpreter {
28642864
args3.push_back(&args2[i]);
28652865
}
28662866
if (nit == nativeCallbacks.end()) {
2867-
throw makeError(ast.location,
2867+
throw makeError(location,
28682868
"unrecognized builtin name: " + builtin_name);
28692869
}
28702870
const VmNativeCallback &cb = nit->second;
@@ -2878,18 +2878,18 @@ class Interpreter {
28782878
} else {
28792879
if (r->kind != JsonnetJsonValue::STRING) {
28802880
throw makeError(
2881-
ast.location,
2881+
location,
28822882
"native extension returned an error that was not a string.");
28832883
}
28842884
std::string rs = r->string;
2885-
throw makeError(ast.location, rs);
2885+
throw makeError(location, rs);
28862886
}
28872887

28882888
} else {
28892889
// Not all arguments forced yet.
28902890
HeapThunk *th = f.thunks[f.elementId++];
28912891
if (!th->filled) {
2892-
stack.newCall(ast.location, th, th->self, th->offset, th->upValues);
2892+
stack.newCall(location, th, th->self, th->offset, th->upValues);
28932893
ast_ = th->body;
28942894
goto recurse;
28952895
} else {

0 commit comments

Comments
 (0)