From 66cc2f2e8873655f8a31a140e7f940eeae3a1577 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 8 Mar 2017 16:48:05 +0100 Subject: [PATCH] fix: ipfs get panic with empty API call License: MIT Signed-off-by: Jakub Sztandera --- core/commands/get.go | 5 +++++ test/sharness/t0090-get.sh | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/commands/get.go b/core/commands/get.go index 4b49e4658f1..bc38c30004e 100644 --- a/core/commands/get.go +++ b/core/commands/get.go @@ -51,6 +51,11 @@ may also specify the level of compression by specifying '-l=<1-9>'. return err }, Run: func(req cmds.Request, res cmds.Response) { + if len(req.Arguments()) == 0 { + res.SetError(errors.New("not enough arugments provided"), cmds.ErrClient) + return + } + cmplvl, err := getCompressOptions(req) if err != nil { res.SetError(err, cmds.ErrClient) diff --git a/test/sharness/t0090-get.sh b/test/sharness/t0090-get.sh index a79827957a4..78bb14427a2 100755 --- a/test/sharness/t0090-get.sh +++ b/test/sharness/t0090-get.sh @@ -141,7 +141,7 @@ test_get_fail() { ' test_expect_success "ipfs get fails" ' - test_expect_code 1 ipfs get QmaGidyrnX8FMbWJoxp8HVwZ1uRKwCyxBJzABnR1S2FVUr + test_expect_code 1 ipfs get QmaGidyrnX8FMbWJoxp8HVwZ1uRKwCyxBJzABnR1S2FVUr ' } @@ -154,6 +154,13 @@ test_get_fail # should work online test_launch_ipfs_daemon test_get_cmd + +test_expect_success "empty request to get doesn't panic and returns error" ' + curl "http://$API_ADDR/api/v0/get" > curl_out || true && + grep "not enough arugments provided" curl_out + + +' test_kill_ipfs_daemon test_done