Commit ed551131 authored by Jeromy's avatar Jeromy

commands: fix panic when expected files field is nil

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent 566c08e2
...@@ -104,13 +104,17 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) { ...@@ -104,13 +104,17 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
contentType := r.Header.Get(contentTypeHeader) contentType := r.Header.Get(contentTypeHeader)
mediatype, _, _ := mime.ParseMediaType(contentType) mediatype, _, _ := mime.ParseMediaType(contentType)
var f *files.MultipartFile var f files.File
if mediatype == "multipart/form-data" { if mediatype == "multipart/form-data" {
f = &files.MultipartFile{Mediatype: mediatype} reader, err := r.MultipartReader()
f.Reader, err = r.MultipartReader()
if err != nil { if err != nil {
return nil, err return nil, err
} }
f = &files.MultipartFile{
Mediatype: mediatype,
Reader: reader,
}
} }
// if there is a required filearg, error if no files were provided // if there is a required filearg, error if no files were provided
......
...@@ -231,7 +231,8 @@ func (r *request) VarArgs(f func(string) error) error { ...@@ -231,7 +231,8 @@ func (r *request) VarArgs(f func(string) error) error {
} }
if r.files == nil { if r.files == nil {
return fmt.Errorf("expected more arguments from stdin") log.Warning("expected more arguments from stdin")
return nil
} }
fi, err := r.files.NextFile() fi, err := r.files.NextFile()
......
...@@ -10,15 +10,23 @@ test_launch_ipfs_daemon ...@@ -10,15 +10,23 @@ test_launch_ipfs_daemon
# Tests go here # Tests go here
test_expect_sucess "commands command with flag flags works via HTTP API - #2301" ' test_expect_success "commands command with flag flags works via HTTP API - #2301" '
curl "http://$API_ADDR/api/v0/commands?flags" | grep "verbose" curl "http://$API_ADDR/api/v0/commands?flags" | grep "verbose"
' '
test_expect_sucess "ipfs refs local over HTTP API returns NDJOSN not flat - #2803" ' test_expect_success "ipfs refs local over HTTP API returns NDJOSN not flat - #2803" '
echo "Hello World" | ipfs add && echo "Hello World" | ipfs add &&
curl "http://$API_ADDR/api/v0/refs/local" | grep "Ref" | grep "Err" curl "http://$API_ADDR/api/v0/refs/local" | grep "Ref" | grep "Err"
' '
test_expect_success "args expecting stdin dont crash when not given" '
curl "$API_ADDR/api/v0/bootstrap/add" > result
'
test_expect_success "no panic traces on daemon" '
test_expect_failure grep "nil pointer dereference" daemon_err
'
test_kill_ipfs_daemon test_kill_ipfs_daemon
test_done test_done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment