mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-04 01:10:49 +01:00
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>
This commit is contained in:
parent
ffc08c1914
commit
a5df7ba6bf
1 changed files with 4 additions and 1 deletions
|
@ -31,7 +31,10 @@ func Open(uriStr string) (io.ReadCloser, error) {
|
||||||
switch strings.ToLower(u.Scheme) {
|
switch strings.ToLower(u.Scheme) {
|
||||||
case "http", "https":
|
case "http", "https":
|
||||||
f, err := http.Get(uriStr)
|
f, err := http.Get(uriStr)
|
||||||
return f.Body, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return f.Body, nil
|
||||||
case "file":
|
case "file":
|
||||||
return os.Open(u.Path)
|
return os.Open(u.Path)
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue