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

src: add missing to_ascii method in dns queries #48347

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
7 changes: 4 additions & 3 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1411,12 +1411,13 @@ static void Query(const FunctionCallbackInfo<Value>& args) {
CHECK(args[1]->IsString());

Local<Object> req_wrap_obj = args[0].As<Object>();
Local<String> string = args[1].As<String>();
auto wrap = std::make_unique<Wrap>(channel, req_wrap_obj);

node::Utf8Value name(env->isolate(), string);
auto plain_name =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this code is safe because it appears that temporary objects are created, and they go out of scope. The result of node::Utf8Value is converted to a string_view, but a string_view pointing at what instance? It is unclear to me.

I recommend breaking this down...

Local<String> string = args[1].As<String>();
node::Utf8Value utf8name(env->isolate(), string);
std::string name = ada::idna::to_ascii(utf8name.ToStringView());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemire Would you like to takeover this pull request? Unfortunately, I can't complete it soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node::Utf8Value(env->isolate(), args[1].As<String>()).ToStringView();
std::string name = ada::idna::to_ascii(plain_name);
channel->ModifyActivityQueryCount(1);
int err = wrap->Send(*name);
int err = wrap->Send(name.data());
if (err) {
channel->ModifyActivityQueryCount(-1);
} else {
Expand Down