@cryptotaxi247 / kubo / commits / 66cc2f2e8

fix: ipfs get panic with empty API call

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Mar 8, 2017 at 16:48 UTC 66cc2f2e8873655f8a31a140e7f940eeae3a1577
2 files changed +13 -1
core/commands/get.go
+5
@@ -51,6 +51,11 @@ may also specify the level of compression by specifying '-l=<1-9>'.
51 return err
52 },
53 Run: func(req cmds.Request, res cmds.Response) {
54 + if len(req.Arguments()) == 0 {
55 + res.SetError(errors.New("not enough arugments provided"), cmds.ErrClient)
56 + return
57 + }
58 +
59 cmplvl, err := getCompressOptions(req)
60 if err != nil {
61 res.SetError(err, cmds.ErrClient)
test/sharness/t0090-get.sh
+8 -1
@@ -141,7 +141,7 @@ test_get_fail() {
141 '
142
143 test_expect_success "ipfs get fails" '
144 - test_expect_code 1 ipfs get QmaGidyrnX8FMbWJoxp8HVwZ1uRKwCyxBJzABnR1S2FVUr
144 + test_expect_code 1 ipfs get QmaGidyrnX8FMbWJoxp8HVwZ1uRKwCyxBJzABnR1S2FVUr
145 '
146 }
147
@@ -154,6 +154,13 @@ test_get_fail
154 # should work online
155 test_launch_ipfs_daemon
156 test_get_cmd
157 +
158 +test_expect_success "empty request to get doesn't panic and returns error" '
159 + curl "http://$API_ADDR/api/v0/get" > curl_out || true &&
160 + grep "not enough arugments provided" curl_out
161 +
162 +
163 +'
164 test_kill_ipfs_daemon
165
166 test_done