Skip to content

Commit

Permalink
fixing bug
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Steurer <[email protected]>
  • Loading branch information
asteurer committed Aug 18, 2024
1 parent 2b32b2b commit ec6f02c
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,23 @@ func ping(w http.ResponseWriter, r *http.Request) {

// validate checks the flag file's content with the request body to see if they match
func validate(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer r.Body.Close()
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer r.Body.Close()

fileBytes, err := os.ReadFile(secretFilePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fileBytes, err := os.ReadFile(secretFilePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if string(fileBytes) == string(bodyBytes) {
w.Write([]byte("Success! You found the flag."))
} else {
w.Write([]byte("The string submitted doesn't match the content of the flag file."))
}
if string(fileBytes) == string(bodyBytes) {
w.Write([]byte("Success! You found the flag."))
} else {
w.Write([]byte("The string submitted doesn't match the content of the flag file."))
}
}

Expand Down

0 comments on commit ec6f02c

Please sign in to comment.