@cryptotaxi247 / kubo / commits / 8a75a8cf0

commands: fix panic when stdin is empty for string args

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

Jeromy committed Aug 7, 2016 at 09:24 UTC 8a75a8cf088beb4e92855c3d26fb3c226cf34916
2 files changed +14
commands/request.go
+6
@@ -240,13 +240,19 @@ func (r *request) VarArgs(f func(string) error) error {
240 return err
241 }
242
243 + var any bool
244 scan := bufio.NewScanner(fi)
245 for scan.Scan() {
246 + any = true
247 err := f(scan.Text())
248 if err != nil {
249 return err
250 }
251 }
252 + if !any {
253 + return f("")
254 + }
255 +
256 return nil
257 }
258
test/sharness/t0050-block.sh
+8
@@ -39,4 +39,12 @@ test_expect_success "'ipfs block get' output looks good" '
39 test_cmp expected_stat actual_stat
40 '
41
42 +test_expect_success "'ipfs block stat' with nothing from stdin doesnt crash" '
43 + test_expect_code 1 ipfs block stat < /dev/null 2> stat_out
44 +'
45 +
46 +test_expect_success "no panic in output" '
47 + test_expect_code 1 grep "panic" stat_out
48 +'
49 +
50 test_done