Skip to content

Commit d742fb1

Browse files
Merge pull request #2989 from ipfs/fix/nil-files-panic
commands: fix panic when expected files field is nil
2 parents 01eb8d7 + ed55113 commit d742fb1

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

commands/http/parse.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
104104
contentType := r.Header.Get(contentTypeHeader)
105105
mediatype, _, _ := mime.ParseMediaType(contentType)
106106

107-
var f *files.MultipartFile
107+
var f files.File
108108
if mediatype == "multipart/form-data" {
109-
f = &files.MultipartFile{Mediatype: mediatype}
110-
f.Reader, err = r.MultipartReader()
109+
reader, err := r.MultipartReader()
111110
if err != nil {
112111
return nil, err
113112
}
113+
114+
f = &files.MultipartFile{
115+
Mediatype: mediatype,
116+
Reader: reader,
117+
}
114118
}
115119

116120
// if there is a required filearg, error if no files were provided

commands/request.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ func (r *request) VarArgs(f func(string) error) error {
231231
}
232232

233233
if r.files == nil {
234-
return fmt.Errorf("expected more arguments from stdin")
234+
log.Warning("expected more arguments from stdin")
235+
return nil
235236
}
236237

237238
fi, err := r.files.NextFile()

test/sharness/t0600-issues-and-regressions-online.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ test_launch_ipfs_daemon
1010

1111
# Tests go here
1212

13-
test_expect_sucess "commands command with flag flags works via HTTP API - #2301" '
13+
test_expect_success "commands command with flag flags works via HTTP API - #2301" '
1414
curl "http://$API_ADDR/api/v0/commands?flags" | grep "verbose"
1515
'
1616

17-
test_expect_sucess "ipfs refs local over HTTP API returns NDJOSN not flat - #2803" '
17+
test_expect_success "ipfs refs local over HTTP API returns NDJOSN not flat - #2803" '
1818
echo "Hello World" | ipfs add &&
1919
curl "http://$API_ADDR/api/v0/refs/local" | grep "Ref" | grep "Err"
2020
'
2121

22+
test_expect_success "args expecting stdin dont crash when not given" '
23+
curl "$API_ADDR/api/v0/bootstrap/add" > result
24+
'
25+
26+
test_expect_success "no panic traces on daemon" '
27+
test_expect_failure grep "nil pointer dereference" daemon_err
28+
'
29+
2230
test_kill_ipfs_daemon
2331

2432
test_done

0 commit comments

Comments
 (0)