commit b155150004b3ae3bef58f6d3096f8c4d91d6a72e
parent 5ed1673d40847153e01d5c83efe6fc373d0062da
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Sat, 13 Jan 2024 13:07:57 +0100
Make static analyzer happy
Diffstat:
1 file changed, 52 insertions(+), 12 deletions(-)
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
@@ -208,7 +208,11 @@ func (t *Registrar) configResponse(w http.ResponseWriter, r *http.Request) {
Version: "0:0:0",
}
w.Header().Set("Content-Type", "application/json")
- response, _ := json.Marshal(cfg)
+ response, err := json.Marshal(cfg)
+ if nil != err {
+ fmt.Println(err)
+ return
+ }
w.Write(response)
}
@@ -224,7 +228,10 @@ func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) {
"zoneKey": t.RootZoneKey,
"error": r.URL.Query().Get("error"),
}
- t.LandingTpl.Execute(w, fullData)
+ err := t.LandingTpl.Execute(w, fullData)
+ if err != nil {
+ fmt.Println(err)
+ }
return
}
@@ -283,7 +290,10 @@ func (t *Registrar) expireRegistration(label string) (err error) {
req.SetBasicAuth(t.GnunetUsername, t.GnunetPassword)
}
resp, err := client.Do(req)
- resp.Body.Close()
+ if err != nil {
+ return err
+ }
+ err = resp.Body.Close()
if err != nil {
return err
}
@@ -310,7 +320,10 @@ func (t *Registrar) createOrUpdateRegistration(nsRecord *NamestoreRecord) (err e
if nil != err {
return err
}
- resp.Body.Close()
+ err = resp.Body.Close()
+ if err != nil {
+ return err
+ }
if http.StatusNoContent != resp.StatusCode {
fmt.Printf("Got error: %d\n", resp.StatusCode)
err = json.NewDecoder(resp.Body).Decode(&gnunetError)
@@ -416,7 +429,12 @@ func (t *Registrar) updateRegistration(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/name/"+vars["label"], http.StatusSeeOther)
return
}
- r.ParseForm()
+ err = r.ParseForm()
+ if nil != err {
+ fmt.Printf("Unable to parse form: " + err.Error())
+ http.Redirect(w, r, "/name/"+vars["label"] + "?error=Form invalid", http.StatusSeeOther)
+ return
+ }
token = r.Form.Get("token")
zkey = r.Form.Get("zkey")
if regMetadata.RegistrationID != token {
@@ -517,7 +535,10 @@ func (t *Registrar) editRegistration(w http.ResponseWriter, r *http.Request) {
"cost": cost,
"suffixHint": t.SuffixHint,
}
- t.EditTpl.Execute(w, fullData)
+ err = t.EditTpl.Execute(w, fullData)
+ if err != nil {
+ fmt.Println(err)
+ }
return
}
@@ -648,7 +669,10 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
"cost": cost,
"suffixHint": t.SuffixHint,
}
- t.BuyTpl.Execute(w, fullData)
+ err = t.BuyTpl.Execute(w, fullData)
+ if err != nil {
+ fmt.Println(err)
+ }
return
}
@@ -678,7 +702,10 @@ func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *Names
if rc == http.StatusNotFound {
if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
fmt.Printf("Registration for %s not found, removing\n", label)
- t.expireRegistration(label)
+ err := t.expireRegistration(label)
+ if nil != err {
+ fmt.Println(err)
+ }
return nil, nil
} else {
return ®Metadata, nil
@@ -722,14 +749,20 @@ func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *Names
// Remove metadata if payment limit exceeded and registration expired
if time.Now().After(regMetadata.NeedsPaymentUntil) && time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
fmt.Printf("Payment request for %s has expired, removing\n", label)
- t.expireRegistration(label)
+ err := t.expireRegistration(label)
+ if nil != err {
+ fmt.Println(err)
+ }
return nil, nil
}
}
} else {
if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
fmt.Printf("Registration for %s has expired, removing\n", label)
- t.expireRegistration(label)
+ err := t.expireRegistration(label)
+ if nil != err {
+ fmt.Println(err)
+ }
return nil, nil
}
}
@@ -826,7 +859,10 @@ func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
"remainingDays": remainingDays,
"registrationSuccess": registered,
}
- t.NameTpl.Execute(w, fullData)
+ err = t.NameTpl.Execute(w, fullData)
+ if err != nil {
+ fmt.Println(err)
+ }
return
}
@@ -859,7 +895,11 @@ func (t *Registrar) Initialize(cfgfile string) {
fmt.Printf("Failed to read config: %v", err)
os.Exit(1)
}
- _cfg.WriteTo(os.Stdout)
+ _, err = _cfg.WriteTo(os.Stdout)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
t.Cfg = _cfg
if t.Cfg.Section("gns-registrar").Key("production").MustBool(false) {
fmt.Println("Production mode enabled")