Merge pull request #2989 from ipfs/fix/nil-files-panic

commands: fix panic when expected files field is nil
This commit is contained in:
Jeromy Johnson 2016-07-26 15:05:27 -07:00 committed by GitHub
commit d742fb137c
3 changed files with 19 additions and 6 deletions

View File

@ -104,13 +104,17 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
contentType := r.Header.Get(contentTypeHeader)
mediatype, _, _ := mime.ParseMediaType(contentType)
var f *files.MultipartFile
var f files.File
if mediatype == "multipart/form-data" {
f = &files.MultipartFile{Mediatype: mediatype}
f.Reader, err = r.MultipartReader()
reader, err := r.MultipartReader()
if err != nil {
return nil, err
}
f = &files.MultipartFile{
Mediatype: mediatype,
Reader: reader,
}
}
// if there is a required filearg, error if no files were provided

View File

@ -231,7 +231,8 @@ func (r *request) VarArgs(f func(string) error) error {
}
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()

View File

@ -10,15 +10,23 @@ test_launch_ipfs_daemon
# 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"
'
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 &&
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_done