Commit d5dbdb27 authored by Chris's avatar Chris Committed by Corey Hulen

several one-line panic, race, and logic fixes (#7766)

parent 9d32cd42
...@@ -45,11 +45,11 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -45,11 +45,11 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
fileData := fileArray[0] fileData := fileArray[0]
file, err := fileData.Open() file, err := fileData.Open()
defer file.Close()
if err != nil { if err != nil {
c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, err.Error(), http.StatusInternalServerError) c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, err.Error(), http.StatusInternalServerError)
return return
} }
defer file.Close()
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
io.Copy(buf, file) io.Copy(buf, file)
......
...@@ -386,10 +386,14 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -386,10 +386,14 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
} }
importFromArray, ok := r.MultipartForm.Value["importFrom"] importFromArray, ok := r.MultipartForm.Value["importFrom"]
if !ok || len(importFromArray) < 1 {
c.Err = model.NewAppError("importTeam", "api.team.import_team.no_import_from.app_error", nil, "", http.StatusBadRequest)
return
}
importFrom := importFromArray[0] importFrom := importFromArray[0]
fileSizeStr, ok := r.MultipartForm.Value["filesize"] fileSizeStr, ok := r.MultipartForm.Value["filesize"]
if !ok { if !ok || len(fileSizeStr) < 1 {
c.Err = model.NewAppError("importTeam", "api.team.import_team.unavailable.app_error", nil, "", http.StatusBadRequest) c.Err = model.NewAppError("importTeam", "api.team.import_team.unavailable.app_error", nil, "", http.StatusBadRequest)
return return
} }
...@@ -414,11 +418,11 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -414,11 +418,11 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
fileInfo := fileInfoArray[0] fileInfo := fileInfoArray[0]
fileData, err := fileInfo.Open() fileData, err := fileInfo.Open()
defer fileData.Close()
if err != nil { if err != nil {
c.Err = model.NewAppError("importTeam", "api.team.import_team.open.app_error", nil, err.Error(), http.StatusBadRequest) c.Err = model.NewAppError("importTeam", "api.team.import_team.open.app_error", nil, err.Error(), http.StatusBadRequest)
return return
} }
defer fileData.Close()
var log *bytes.Buffer var log *bytes.Buffer
switch importFrom { switch importFrom {
......
...@@ -156,8 +156,8 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -156,8 +156,8 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
commands := []*model.Command{} var commands []*model.Command
err := &model.AppError{} var err *model.AppError
if customOnly { if customOnly {
if !c.App.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) { if !c.App.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
c.SetPermissionError(model.PERMISSION_MANAGE_SLASH_COMMANDS) c.SetPermissionError(model.PERMISSION_MANAGE_SLASH_COMMANDS)
......
...@@ -315,11 +315,11 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -315,11 +315,11 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
fileData := fileArray[0] fileData := fileArray[0]
file, err := fileData.Open() file, err := fileData.Open()
defer file.Close()
if err != nil { if err != nil {
c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, err.Error(), http.StatusBadRequest) c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, err.Error(), http.StatusBadRequest)
return return
} }
defer file.Close()
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
io.Copy(buf, file) io.Copy(buf, file)
......
...@@ -623,10 +623,14 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -623,10 +623,14 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
} }
importFromArray, ok := r.MultipartForm.Value["importFrom"] importFromArray, ok := r.MultipartForm.Value["importFrom"]
if !ok || len(importFromArray) < 1 {
c.Err = model.NewAppError("importTeam", "api.team.import_team.no_import_from.app_error", nil, "", http.StatusBadRequest)
return
}
importFrom := importFromArray[0] importFrom := importFromArray[0]
fileSizeStr, ok := r.MultipartForm.Value["filesize"] fileSizeStr, ok := r.MultipartForm.Value["filesize"]
if !ok { if !ok || len(fileSizeStr) < 1 {
c.Err = model.NewAppError("importTeam", "api.team.import_team.unavailable.app_error", nil, "", http.StatusBadRequest) c.Err = model.NewAppError("importTeam", "api.team.import_team.unavailable.app_error", nil, "", http.StatusBadRequest)
return return
} }
...@@ -651,11 +655,11 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -651,11 +655,11 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
fileInfo := fileInfoArray[0] fileInfo := fileInfoArray[0]
fileData, err := fileInfo.Open() fileData, err := fileInfo.Open()
defer fileData.Close()
if err != nil { if err != nil {
c.Err = model.NewAppError("importTeam", "api.team.import_team.open.app_error", nil, err.Error(), http.StatusBadRequest) c.Err = model.NewAppError("importTeam", "api.team.import_team.open.app_error", nil, err.Error(), http.StatusBadRequest)
return return
} }
defer fileData.Close()
var log *bytes.Buffer var log *bytes.Buffer
switch importFrom { switch importFrom {
......
...@@ -44,6 +44,9 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) { ...@@ -44,6 +44,9 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) {
path, _ := utils.FindDir("web/static/images") path, _ := utils.FindDir("web/static/images")
file, err := os.Open(path + "/" + filename) file, err := os.Open(path + "/" + filename)
if err != nil {
return nil, false
}
defer file.Close() defer file.Close()
data := &bytes.Buffer{} data := &bytes.Buffer{}
......
...@@ -1185,7 +1185,7 @@ func (a *App) ViewChannel(view *model.ChannelView, userId string, clearPushNotif ...@@ -1185,7 +1185,7 @@ func (a *App) ViewChannel(view *model.ChannelView, userId string, clearPushNotif
} }
} }
times := map[string]int64{} var times map[string]int64
if result := <-uchan; result.Err != nil { if result := <-uchan; result.Err != nil {
return nil, result.Err return nil, result.Err
} else { } else {
......
...@@ -259,10 +259,10 @@ func (a *App) UploadFiles(teamId string, channelId string, userId string, fileHe ...@@ -259,10 +259,10 @@ func (a *App) UploadFiles(teamId string, channelId string, userId string, fileHe
for i, fileHeader := range fileHeaders { for i, fileHeader := range fileHeaders {
file, fileErr := fileHeader.Open() file, fileErr := fileHeader.Open()
defer file.Close()
if fileErr != nil { if fileErr != nil {
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.bad_parse.app_error", nil, fileErr.Error(), http.StatusBadRequest) return nil, model.NewAppError("UploadFiles", "api.file.upload_file.bad_parse.app_error", nil, fileErr.Error(), http.StatusBadRequest)
} }
defer file.Close()
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
io.Copy(buf, file) io.Copy(buf, file)
......
...@@ -36,10 +36,10 @@ func WriteSamlFile(fileData *multipart.FileHeader) *model.AppError { ...@@ -36,10 +36,10 @@ func WriteSamlFile(fileData *multipart.FileHeader) *model.AppError {
} }
file, err := fileData.Open() file, err := fileData.Open()
defer file.Close()
if err != nil { if err != nil {
return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.open.app_error", nil, err.Error(), http.StatusInternalServerError) return model.NewAppError("AddSamlCertificate", "api.admin.add_certificate.open.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
defer file.Close()
configDir, _ := utils.FindDir("config") configDir, _ := utils.FindDir("config")
out, err := os.Create(configDir + filename) out, err := os.Create(configDir + filename)
......
...@@ -774,10 +774,10 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) ...@@ -774,10 +774,10 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
func (a *App) SetProfileImage(userId string, imageData *multipart.FileHeader) *model.AppError { func (a *App) SetProfileImage(userId string, imageData *multipart.FileHeader) *model.AppError {
file, err := imageData.Open() file, err := imageData.Open()
defer file.Close()
if err != nil { if err != nil {
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.open.app_error", nil, err.Error(), http.StatusBadRequest) return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.open.app_error", nil, err.Error(), http.StatusBadRequest)
} }
defer file.Close()
// Decode image config first to check dimensions before loading the whole thing into memory later on // Decode image config first to check dimensions before loading the whole thing into memory later on
config, _, err := image.DecodeConfig(file) config, _, err := image.DecodeConfig(file)
......
...@@ -46,7 +46,7 @@ func jobserverCmdF(cmd *cobra.Command, args []string) { ...@@ -46,7 +46,7 @@ func jobserverCmdF(cmd *cobra.Command, args []string) {
a.Jobs.StartSchedulers() a.Jobs.StartSchedulers()
} }
var signalChan chan os.Signal = make(chan os.Signal) signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-signalChan <-signalChan
......
...@@ -144,7 +144,7 @@ func runServer(configFileLocation string) { ...@@ -144,7 +144,7 @@ func runServer(configFileLocation string) {
// wait for kill signal before attempting to gracefully shutdown // wait for kill signal before attempting to gracefully shutdown
// the running service // the running service
c := make(chan os.Signal) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-c <-c
......
...@@ -77,7 +77,7 @@ func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error { ...@@ -77,7 +77,7 @@ func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error {
wsapi.Init(a, a.Srv.WebSocketRouter) wsapi.Init(a, a.Srv.WebSocketRouter)
a.UpdateConfig(setupClientTests) a.UpdateConfig(setupClientTests)
c := make(chan os.Signal) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-c <-c
......
...@@ -2171,6 +2171,10 @@ ...@@ -2171,6 +2171,10 @@
"id": "api.team.import_team.parse.app_error", "id": "api.team.import_team.parse.app_error",
"translation": "Could not parse multipart form" "translation": "Could not parse multipart form"
}, },
{
"id": "api.team.import_team.no_import_from.app_error",
"translation": "Malformed request: importFrom field is not present."
},
{ {
"id": "api.team.import_team.unavailable.app_error", "id": "api.team.import_team.unavailable.app_error",
"translation": "Malformed request: filesize field is not present." "translation": "Malformed request: filesize field is not present."
......
...@@ -138,18 +138,16 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) { ...@@ -138,18 +138,16 @@ func manualTest(c *api.Context, w http.ResponseWriter, r *http.Request) {
// Grab the test ID and pick the test // Grab the test ID and pick the test
testname, ok := params["test"] testname, ok := params["test"]
var err2 *model.AppError if !ok {
c.Err = model.NewAppError("/manual", "manaultesting.manual_test.parse.app_error", nil, "", http.StatusBadRequest)
return
}
switch testname[0] { switch testname[0] {
case "autolink": case "autolink":
err2 = testAutoLink(env) c.Err = testAutoLink(env)
// ADD YOUR NEW TEST HERE! // ADD YOUR NEW TEST HERE!
case "general": case "general":
err2 = nil
}
if err != nil {
c.Err = err2
return
} }
} }
......
...@@ -46,7 +46,6 @@ func userFromGitLabUser(glu *GitLabUser) *model.User { ...@@ -46,7 +46,6 @@ func userFromGitLabUser(glu *GitLabUser) *model.User {
} else { } else {
user.FirstName = glu.Name user.FirstName = glu.Name
} }
strings.TrimSpace(user.Email)
user.Email = glu.Email user.Email = glu.Email
userId := strconv.FormatInt(glu.Id, 10) userId := strconv.FormatInt(glu.Id, 10)
user.AuthData = &userId user.AuthData = &userId
......
...@@ -104,10 +104,10 @@ func ReadFile(path string) ([]byte, *model.AppError) { ...@@ -104,10 +104,10 @@ func ReadFile(path string) ([]byte, *model.AppError) {
} }
bucket := Cfg.FileSettings.AmazonS3Bucket bucket := Cfg.FileSettings.AmazonS3Bucket
minioObject, err := s3Clnt.GetObject(bucket, path) minioObject, err := s3Clnt.GetObject(bucket, path)
defer minioObject.Close()
if err != nil { if err != nil {
return nil, model.NewAppError("ReadFile", "api.file.read_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("ReadFile", "api.file.read_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
defer minioObject.Close()
if f, err := ioutil.ReadAll(minioObject); err != nil { if f, err := ioutil.ReadAll(minioObject); err != nil {
return nil, model.NewAppError("ReadFile", "api.file.read_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("ReadFile", "api.file.read_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment