Skip to content

src: improve error handling in node_http2 #57764

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 63 additions & 21 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,13 @@ Http2Priority::Http2Priority(Environment* env,
Local<Value> weight,
Local<Value> exclusive) {
Local<Context> context = env->context();
int32_t parent_ = parent->Int32Value(context).ToChecked();
int32_t weight_ = weight->Int32Value(context).ToChecked();
int32_t parent_;
int32_t weight_;
if (!parent->Int32Value(context).To(&parent_) ||
!weight->Int32Value(context).To(&weight_)) {
nghttp2_priority_spec_init(this, 0, 0, 0);
return;
}
bool exclusive_ = exclusive->IsTrue();
Debug(env, DebugCategory::HTTP2STREAM,
"Http2Priority: parent: %d, weight: %d, exclusive: %s\n",
Expand Down Expand Up @@ -2715,11 +2720,12 @@ void Http2Stream::DecrementAvailableOutboundLength(size_t amount) {
// back to JS land
void HttpErrorString(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
uint32_t val = args[0]->Uint32Value(env->context()).ToChecked();
args.GetReturnValue().Set(
OneByteString(
env->isolate(),
reinterpret_cast<const uint8_t*>(nghttp2_strerror(val))));
uint32_t val;
if (args[0]->Uint32Value(env->context()).To(&val)) {
args.GetReturnValue().Set(
OneByteString(env->isolate(),
reinterpret_cast<const uint8_t*>(nghttp2_strerror(val))));
}
}


Expand All @@ -2744,7 +2750,10 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Http2Session* session;
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
int32_t id = args[0]->Int32Value(env->context()).ToChecked();
int32_t id;
if (!args[0]->Int32Value(env->context()).To(&id)) {
return;
}
if (nghttp2_session_set_next_stream_id(session->session(), id) < 0) {
Debug(session, "failed to set next stream id to %d", id);
return args.GetReturnValue().Set(false);
Expand All @@ -2762,7 +2771,10 @@ void Http2Session::SetLocalWindowSize(
Http2Session* session;
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());

int32_t window_size = args[0]->Int32Value(env->context()).ToChecked();
int32_t window_size;
if (!args[0]->Int32Value(env->context()).To(&window_size)) {
return;
}

int result = nghttp2_session_set_local_window_size(
session->session(), NGHTTP2_FLAG_NONE, 0, window_size);
Expand Down Expand Up @@ -2822,8 +2834,11 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
Http2State* state = realm->GetBindingData<Http2State>();

CHECK(args.IsConstructCall());
SessionType type = static_cast<SessionType>(
args[0]->Int32Value(realm->context()).ToChecked());
int32_t val;
if (!args[0]->Int32Value(realm->context()).To(&val)) {
return;
}
SessionType type = static_cast<SessionType>(val);
Http2Session* session = new Http2Session(state, args.This(), type);
Debug(session, "session created");
}
Expand All @@ -2845,7 +2860,10 @@ void Http2Session::Destroy(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<Context> context = env->context();

uint32_t code = args[0]->Uint32Value(context).ToChecked();
uint32_t code;
if (!args[0]->Uint32Value(context).To(&code)) {
return;
}
session->Close(code, args[1]->IsTrue());
}

Expand All @@ -2857,7 +2875,10 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
Environment* env = session->env();

Local<Array> headers = args[0].As<Array>();
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
int32_t options;
if (!args[1]->Int32Value(env->context()).To(&options)) {
return;
}

Debug(session, "request submitted");

Expand Down Expand Up @@ -2906,8 +2927,14 @@ void Http2Session::Goaway(const FunctionCallbackInfo<Value>& args) {
Http2Session* session;
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());

uint32_t code = args[0]->Uint32Value(context).ToChecked();
int32_t lastStreamID = args[1]->Int32Value(context).ToChecked();
uint32_t code;
if (!args[0]->Uint32Value(context).To(&code)) {
return;
}
int32_t lastStreamID;
if (!args[1]->Int32Value(context).To(&lastStreamID)) {
return;
}
ArrayBufferViewContents<uint8_t> opaque_data;

if (args[2]->IsArrayBufferView()) {
Expand Down Expand Up @@ -2945,7 +2972,10 @@ void Http2Stream::RstStream(const FunctionCallbackInfo<Value>& args) {
Local<Context> context = env->context();
Http2Stream* stream;
ASSIGN_OR_RETURN_UNWRAP(&stream, args.This());
uint32_t code = args[0]->Uint32Value(context).ToChecked();
uint32_t code;
if (!args[0]->Uint32Value(context).To(&code)) {
return;
}
Debug(stream, "sending rst_stream with code %d", code);
stream->SubmitRstStream(code);
}
Expand All @@ -2958,7 +2988,10 @@ void Http2Stream::Respond(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&stream, args.This());

Local<Array> headers = args[0].As<Array>();
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
int32_t options;
if (!args[1]->Int32Value(env->context()).To(&options)) {
return;
}

args.GetReturnValue().Set(
stream->SubmitResponse(
Expand Down Expand Up @@ -3013,7 +3046,10 @@ void Http2Stream::PushPromise(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&parent, args.This());

Local<Array> headers = args[0].As<Array>();
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
int32_t options;
if (!args[1]->Int32Value(env->context()).To(&options)) {
return;
}

Debug(parent, "creating push promise");

Expand Down Expand Up @@ -3108,7 +3144,10 @@ void Http2Session::AltSvc(const FunctionCallbackInfo<Value>& args) {
Http2Session* session;
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());

int32_t id = args[0]->Int32Value(env->context()).ToChecked();
int32_t id;
if (!args[0]->Int32Value(env->context()).To(&id)) {
return;
}

// origin and value are both required to be ASCII, handle them as such.
Local<String> origin_str;
Expand Down Expand Up @@ -3142,9 +3181,12 @@ void Http2Session::Origin(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());

Local<String> origin_string = args[0].As<String>();
size_t count = args[1]->Int32Value(context).ToChecked();
int32_t count;
if (!args[1]->Int32Value(context).To(&count)) {
return;
}

session->Origin(Origins(env, origin_string, count));
session->Origin(Origins(env, origin_string, static_cast<size_t>(count)));
}

// Submits a PING frame to be sent to the connected peer.
Expand Down
Loading