aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeripath2021-12-26 09:22:10 +0000
committerGitHub2021-12-26 09:22:10 +0000
commitafe9d2cadd8ee778f698d5b2874b74b09c7d7d9d (patch)
treec0bf4bb75467754333b2cdc3156c09a8d48ea4f4
parent012e45a4c1bbcf48bb7c1328caa7db5f30440cad (diff)
Prevent NPE if gitea uploader fails to open url (#18080) (#18101)
Backport #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>
-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 0967a0802..74410f43f 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: