From a5df7ba6bf57c764b1c5e4c67dbbdf5b115765c9 Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 23 Dec 2021 16:27:33 +0000 Subject: [PATCH] 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 --- 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: