Skip to content

Commit

Permalink
Merge pull request #3050 from ipfs/fix/stdin-zero-panic
Browse files Browse the repository at this point in the history
commands: fix panic when stdin is empty for string args
  • Loading branch information
whyrusleeping authored Aug 7, 2016
2 parents 6e5d0ab + 8a75a8c commit 16f8570
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions commands/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,19 @@ func (r *request) VarArgs(f func(string) error) error {
return err
}

var any bool
scan := bufio.NewScanner(fi)
for scan.Scan() {
any = true
err := f(scan.Text())
if err != nil {
return err
}
}
if !any {
return f("")
}

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions test/sharness/t0050-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ test_expect_success "'ipfs block get' output looks good" '
test_cmp expected_stat actual_stat
'

test_expect_success "'ipfs block stat' with nothing from stdin doesnt crash" '
test_expect_code 1 ipfs block stat < /dev/null 2> stat_out
'

test_expect_success "no panic in output" '
test_expect_code 1 grep "panic" stat_out
'

test_done

0 comments on commit 16f8570

Please sign in to comment.