Skip to content

Commit

Permalink
Merge pull request #2989 from ipfs/fix/nil-files-panic
Browse files Browse the repository at this point in the history
commands: fix panic when expected files field is nil
  • Loading branch information
whyrusleeping authored Jul 26, 2016
2 parents 01eb8d7 + ed55113 commit d742fb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 7 additions & 3 deletions commands/http/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion commands/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions test/sharness/t0600-issues-and-regressions-online.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d742fb1

Please sign in to comment.