Skip to content

Commit

Permalink
Merge pull request #785 from skrashevich/exit-code-check
Browse files Browse the repository at this point in the history
Ensure exit code is within valid range
  • Loading branch information
AlexxIT authored Nov 29, 2023
2 parents 94aced0 + 7ac5b4f commit 0def6f8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ func exitHandler(w http.ResponseWriter, r *http.Request) {
}

s := r.URL.Query().Get("code")
code, _ := strconv.Atoi(s)
code, err := strconv.Atoi(s)

// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02
if err != nil || code < 0 || code > 125 {
http.Error(w, "Code must be in the range [0, 125]", http.StatusBadRequest)
return
}

os.Exit(code)
}

Expand Down

0 comments on commit 0def6f8

Please sign in to comment.