1
0
Fork 0

it's dangerous to read from TryCatch if it has not been properly populated before (#4567)

This commit is contained in:
Jan 2018-02-12 11:59:23 +01:00 committed by GitHub
parent 3b6abfd4a8
commit 399d2e67f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 18 deletions

View File

@ -82,7 +82,13 @@ Result executeTransaction(
if (tryCatch.HasCaught()) {
//we have some javascript error that is not an arangoError
std::string msg = *v8::String::Utf8Value(tryCatch.Message()->Get());
std::string msg;
if (!tryCatch.Message().IsEmpty()) {
v8::String::Utf8Value m(tryCatch.Message()->Get());
if (*m != nullptr) {
msg = *m;
}
}
rv.reset(TRI_ERROR_HTTP_SERVER_ERROR, msg);
}
@ -287,12 +293,20 @@ Result executeTransactionJS(
action = v8::Local<v8::Function>::Cast(function);
if (tryCatch.HasCaught()) {
if (!tryCatch.Message().IsEmpty()) {
v8::String::Utf8Value tryCatchMessage(tryCatch.Message()->Get());
if (*tryCatchMessage != nullptr) {
actionError += " - ";
actionError += *v8::String::Utf8Value(tryCatch.Message()->Get());
actionError += *tryCatchMessage;
}
}
v8::String::Utf8Value tryCatchStackTrace(tryCatch.StackTrace());
if (*tryCatchStackTrace != nullptr) {
actionError += " - ";
actionError += *v8::String::Utf8Value(tryCatch.StackTrace());
actionError += *tryCatchStackTrace;
}
rv.reset(TRI_ERROR_BAD_PARAMETER, actionError);
tryCatch.Reset(); //reset as we have transferd the error message into the Result
tryCatch.Reset(); //reset as we have transferred the error message into the Result
return rv;
}
action->SetName(TRI_V8_ASCII_STRING(isolate, "userTransactionSource"));

View File

@ -418,10 +418,12 @@ static void JS_Parse(v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Local<v8::Object> exceptionObj =
tryCatch.Exception().As<v8::Object>();
v8::Handle<v8::Message> message = tryCatch.Message();
if (!message.IsEmpty()) {
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "lineNumber"),
v8::Number::New(isolate, message->GetLineNumber()));
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "columnNumber"),
v8::Number::New(isolate, message->GetStartColumn()));
}
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "fileName"), filename->ToString());
tryCatch.ReThrow();
return;
@ -489,10 +491,12 @@ static void JS_ParseFile(v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Local<v8::Object> exceptionObj =
tryCatch.Exception().As<v8::Object>();
v8::Handle<v8::Message> message = tryCatch.Message();
if (!message.IsEmpty()) {
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "lineNumber"),
v8::Number::New(isolate, message->GetLineNumber()));
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "columnNumber"),
v8::Number::New(isolate, message->GetStartColumn()));
}
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "fileName"), args[0]);
tryCatch.ReThrow();
return;
@ -1046,10 +1050,12 @@ static void JS_Execute(v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Local<v8::Object> exceptionObj =
tryCatch.Exception().As<v8::Object>();
v8::Handle<v8::Message> message = tryCatch.Message();
if (!message.IsEmpty()) {
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "lineNumber"),
v8::Number::New(isolate, message->GetLineNumber()));
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "columnNumber"),
v8::Number::New(isolate, message->GetStartColumn()));
}
exceptionObj->Set(TRI_V8_ASCII_STRING(isolate, "fileName"),
filename->ToString());
tryCatch.ReThrow();