Skip to content

Commit afe9d2c

Browse files
authored
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 <[email protected]>
1 parent 012e45a commit afe9d2c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/uri/uri.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ func Open(uriStr string) (io.ReadCloser, error) {
3131
switch strings.ToLower(u.Scheme) {
3232
case "http", "https":
3333
f, err := http.Get(uriStr)
34-
return f.Body, err
34+
if err != nil {
35+
return nil, err
36+
}
37+
return f.Body, nil
3538
case "file":
3639
return os.Open(u.Path)
3740
default:

0 commit comments

Comments
 (0)