From 514535a60767f1dfd29552e969e917b50fa9f1cb Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Wed, 30 Jan 2019 21:25:09 -0500 Subject: [PATCH] oauth_google_callback.go: fix potential nil panic --- api/oauth_google_callback.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/api/oauth_google_callback.go b/api/oauth_google_callback.go index e647281..0a1108f 100644 --- a/api/oauth_google_callback.go +++ b/api/oauth_google_callback.go @@ -39,7 +39,14 @@ func googleCallbackHandler(w http.ResponseWriter, r *http.Request) { return } - c, err := commenterGetByEmail("google", user["email"].(string)) + if user["email"] == nil { + fmt.Fprintf(w, "Error: no email address returned by Github") + return + } + + email := user["email"].(string) + + c, err := commenterGetByEmail("google", email) if err != nil && err != errorNoSuchCommenter { fmt.Fprintf(w, "Error: %s", err.Error()) return @@ -49,14 +56,6 @@ func googleCallbackHandler(w http.ResponseWriter, r *http.Request) { // TODO: in case of returning users, update the information we have on record? if err == errorNoSuchCommenter { - var email string - if _, ok := user["email"]; ok { - email = user["email"].(string) - } else { - fmt.Fprintf(w, "Error: %s", errorInvalidEmail.Error()) - return - } - var link string if val, ok := user["link"]; ok { link = val.(string)