aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-12-23 16:27:33 +0000
committerGitHub <noreply@github.com>2021-12-23 16:27:33 +0000
commita5df7ba6bf57c764b1c5e4c67dbbdf5b115765c9 (patch)
tree4cf3be8c68ed7625e663e039a596b577769ea4b8 /modules
parentffc08c1914fbe6a5a5ebe9c8571b790ac6024d71 (diff)
downloadgitea-a5df7ba6bf57c764b1c5e4c67dbbdf5b115765c9.tar.gz
gitea-a5df7ba6bf57c764b1c5e4c67dbbdf5b115765c9.zip
Prevent NPE if gitea uploader fails to open url (#18080)
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>
Diffstat (limited to 'modules')
-rw-r--r--modules/uri/uri.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/modules/uri/uri.go b/modules/uri/uri.go
index 0967a0802f..74410f43f9 100644
--- a/modules/uri/uri.go
+++ b/modules/uri/uri.go
@@ -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: