Skip to content

Commit

Permalink
webserver: Ensure sub forms are not nil. (#3006)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins authored Oct 6, 2024
1 parent bf667e8 commit 9b68c52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ func (s *WebServer) apiTrade(w http.ResponseWriter, r *http.Request) {
return
}
defer zero(pass)
if form.Order == nil {
s.writeAPIError(w, errors.New("order missing"))
return
}
ord, err := s.core.Trade(pass, form.Order)
if err != nil {
s.writeAPIError(w, fmt.Errorf("error placing order: %w", err))
Expand Down Expand Up @@ -748,6 +752,10 @@ func (s *WebServer) apiAccountImport(w http.ResponseWriter, r *http.Request) {
return
}
defer zero(pass)
if form.Account == nil {
s.writeAPIError(w, errors.New("account missing"))
return
}
err = s.core.AccountImport(pass, form.Account, form.Bonds)
if err != nil {
s.writeAPIError(w, fmt.Errorf("error importing account: %w", err))
Expand Down Expand Up @@ -1668,6 +1676,11 @@ func (s *WebServer) apiRunLogs(w http.ResponseWriter, r *http.Request) {
return
}

if req.Market == nil {
s.writeAPIError(w, errors.New("market missing"))
return
}

logs, updatedLogs, overview, err := s.mm.RunLogs(req.StartTime, req.Market, req.N, req.RefID, req.Filters)
if err != nil {
s.writeAPIError(w, fmt.Errorf("error getting run logs: %w", err))
Expand Down Expand Up @@ -1888,6 +1901,11 @@ func (s *WebServer) apiStartMarketMakingBot(w http.ResponseWriter, r *http.Reque
s.writeAPIError(w, fmt.Errorf("password error: %w", err))
return
}
defer zero(appPW)
if form.Config == nil {
s.writeAPIError(w, errors.New("config missing"))
return
}
if err = s.mm.StartBot(form.Config, nil, appPW); err != nil {
s.writeAPIError(w, fmt.Errorf("error starting market making: %v", err))
return
Expand All @@ -1904,6 +1922,10 @@ func (s *WebServer) apiStopMarketMakingBot(w http.ResponseWriter, r *http.Reques
s.writeAPIError(w, fmt.Errorf("failed to read form"))
return
}
if form.Market == nil {
s.writeAPIError(w, errors.New("market missing"))
return
}
if err := s.mm.StopBot(form.Market); err != nil {
s.writeAPIError(w, fmt.Errorf("error stopping mm bot %q: %v", form.Market, err))
return
Expand Down
3 changes: 2 additions & 1 deletion client/webserver/webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ func testTrade(t *testing.T, async bool) {
reader := new(TReader)

body := &tradeForm{
Pass: []byte("random"),
Pass: []byte("random"),
Order: new(core.TradeForm),
}

ensure := func(want string) {
Expand Down

0 comments on commit 9b68c52

Please sign in to comment.