Stricter arg length checks
This commit is contained in:
parent
c0c77b24f8
commit
0fc9a3db2f
@ -24,6 +24,11 @@ using namespace v8;
|
||||
template <typename APP>
|
||||
void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
|
||||
/* pattern, behavior */
|
||||
if (missingArguments(2, args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
|
||||
PerContextData *perContextData = (PerContextData *) Local<External>::Cast(args.Data())->Value();
|
||||
@ -288,9 +293,7 @@ void uWS_App_listen(const FunctionCallbackInfo<Value> &args) {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
|
||||
/* Require at least two arguments */
|
||||
if (args.Length() < 2) {
|
||||
/* Throw here */
|
||||
args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "App.listen requires port and callback", NewStringType::kNormal).ToLocalChecked()));
|
||||
if (missingArguments(2, args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -332,7 +335,7 @@ void uWS_App_publish(const FunctionCallbackInfo<Value> &args) {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
|
||||
/* topic, message [isBinary, compress] */
|
||||
if (args.Length() < 2) {
|
||||
if (missingArguments(2, args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,17 @@ static constexpr int getAppTypeIndex() {
|
||||
return std::is_same<APP, uWS::SSLApp>::value;
|
||||
}
|
||||
|
||||
static inline bool missingArguments(int length, const FunctionCallbackInfo<Value> &args) {
|
||||
if (args.Length() < length) {
|
||||
std::string message = "Function requires at least ";
|
||||
message += std::to_string(length);
|
||||
message += " arguments.";
|
||||
args.GetReturnValue().Set(args.GetIsolate()->ThrowException(String::NewFromUtf8(args.GetIsolate(), message.c_str(), NewStringType::kNormal).ToLocalChecked()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct Callback {
|
||||
bool invalid = false;
|
||||
UniquePersistent<Function> f;
|
||||
|
@ -74,6 +74,10 @@ struct WebSocketWrapper {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
auto *ws = getWebSocket<SSL>(args);
|
||||
if (ws) {
|
||||
if (missingArguments(2, args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NativeString topic(isolate, args[0]);
|
||||
if (topic.isInvalid(args)) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user