Skip to content

Commit

Permalink
Prevent NPE if gitea uploader fails to open url (go-gitea#18080)
Browse files Browse the repository at this point in the history
If http.Get() returns an error return nil and err before attempting to
use the broken file.

Thanks to walker xiong for spotting this bug.

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored and Stelios Malathouras committed Mar 28, 2022
1 parent c9e893d commit 4ce57b8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/uri/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func Open(uriStr string) (io.ReadCloser, error) {
switch strings.ToLower(u.Scheme) {
case "http", "https":
f, err := http.Get(uriStr)
return f.Body, err
if err != nil {
return nil, err
}
return f.Body, nil
case "file":
return os.Open(u.Path)
default:
Expand Down

0 comments on commit 4ce57b8

Please sign in to comment.