summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-05-16 12:48:55 +0700
committerShulhan <ms@kilabit.info>2023-05-16 12:48:55 +0700
commit0820f2234c014bb205e1e7cb405e0ad014b7ff12 (patch)
tree27166800bc1865bd09c050d12953dd80154528d5
parentc484bc6ec480dd799c491b3dd0f673f822c3b484 (diff)
downloadgorankusu-0820f2234c014bb205e1e7cb405e0ad014b7ff12.tar.xz
all: fix panic when attacking HTTP due to nil Attack handler
In attack endpoint, check if the Attack is nil before we push the request to attack queue.
-rw-r--r--errors.go8
-rw-r--r--trunks.go3
2 files changed, 11 insertions, 0 deletions
diff --git a/errors.go b/errors.go
index 7f08980..2da10e6 100644
--- a/errors.go
+++ b/errors.go
@@ -35,6 +35,14 @@ func errAttackNotAllowed() error {
return res
}
+var errAttackHandlerNotSet = libhttp.EndpointResponse{
+ E: liberrors.E{
+ Code: http.StatusNotAcceptable,
+ Message: `the Attack handler is not set`,
+ Name: `ERR_ATTACK_HANDLER_NOT_SET`,
+ },
+}
+
func errInternal(err error) error {
res := &libhttp.EndpointResponse{
E: liberrors.E{
diff --git a/trunks.go b/trunks.go
index b566a05..6037f4f 100644
--- a/trunks.go
+++ b/trunks.go
@@ -108,6 +108,9 @@ func (trunks *Trunks) AttackHttp(req *RunRequest) (err error) {
if !origHttpTarget.AllowAttack {
return errAttackNotAllowed()
}
+ if origHttpTarget.Attack == nil {
+ return fmt.Errorf(`%s: %w`, logp, &errAttackHandlerNotSet)
+ }
req = generateRunRequest(trunks.Env, req, origTarget, origHttpTarget)