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

Fix NodeJS SecureSession handling nullptr #698

Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 0 deletions src/wrappers/themis/jsthemis/secure_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ void SecureSession::New(const Nan::FunctionCallbackInfo<v8::Value>& args)
return;
}
SecureSession* obj = new SecureSession(id, private_key, v8::Local<v8::Function>::Cast(args[2]));
if (!obj->isCreated()) {
// secure_session_create() inside SecureSession::SecureSession()
// may fail, we need to catch this and throw exception to JS
ThrowParameterError("SecureSession", "unsupported private key");
args.GetReturnValue().SetUndefined();
Comment on lines +150 to +153
Copy link
Collaborator

Choose a reason for hiding this comment

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

Initially I wanted to note that there may be other reasons for a failure here, but most of them are actually checked and reported before this call. It can still fail due to allocation errors and such but that's rare so I think this message should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, secure_session_create() only gives NULL or some valid pointer, and we can't get the actual error code in case of error.

return;
}
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/wrappers/themis/jsthemis/secure_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class SecureSession : public Nan::ObjectWrap
public:
static void Init(v8::Local<v8::Object> exports);

bool isCreated()
{
return session_ != nullptr;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this method can be private.

(I know, no one really cares in this case, but good habits are important.)

Copy link
Contributor

Choose a reason for hiding this comment

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

agree


private:
explicit SecureSession(const std::vector<uint8_t>& id,
const std::vector<uint8_t>& private_key,
Expand Down