From afe9d2cadd8ee778f698d5b2874b74b09c7d7d9d Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 26 Dec 2021 09:22:10 +0000 Subject: [PATCH] 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 --- modules/uri/uri.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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: