@cryptotaxi247 / kubo / commits / ed551131f

commands: fix panic when expected files field is nil

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Jul 25, 2016 at 09:12 UTC ed551131f2cd1946628f3650011499fc498968e8
3 files changed +19 -6
commands/http/parse.go
+7 -3
@@ -104,13 +104,17 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
104 contentType := r.Header.Get(contentTypeHeader)
105 mediatype, _, _ := mime.ParseMediaType(contentType)
106
107 - var f *files.MultipartFile
107 + var f files.File
108 if mediatype == "multipart/form-data" {
109 - f = &files.MultipartFile{Mediatype: mediatype}
110 - f.Reader, err = r.MultipartReader()
109 + reader, err := r.MultipartReader()
110 if err != nil {
111 return nil, err
112 }
113 +
114 + f = &files.MultipartFile{
115 + Mediatype: mediatype,
116 + Reader: reader,
117 + }
118 }
119
120 // if there is a required filearg, error if no files were provided
commands/request.go
+2 -1
@@ -231,7 +231,8 @@ func (r *request) VarArgs(f func(string) error) error {
231 }
232
233 if r.files == nil {
234 - return fmt.Errorf("expected more arguments from stdin")
234 + log.Warning("expected more arguments from stdin")
235 + return nil
236 }
237
238 fi, err := r.files.NextFile()
test/sharness/t0600-issues-and-regressions-online.sh
+10 -2
@@ -10,15 +10,23 @@ test_launch_ipfs_daemon
10
11 # Tests go here
12
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" '
14 curl "http://$API_ADDR/api/v0/commands?flags" | grep "verbose"
15 '
16
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" '
18 echo "Hello World" | ipfs add &&
19 curl "http://$API_ADDR/api/v0/refs/local" | grep "Ref" | grep "Err"
20 '
21
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 +
30 test_kill_ipfs_daemon
31
32 test_done