Skip to content

Commit

Permalink
block: sed-opal: Fix a couple off by one bugs
Browse files Browse the repository at this point in the history
resp->num is the number of tokens in resp->tok[].  It gets set in
response_parse().  So if n == resp->num then we're reading beyond the
end of the data.

Fixes: 455a7b2 ("block: Add Sed-opal library")
Reviewed-by: Scott Bauer <[email protected]>
Tested-by: Scott Bauer <[email protected]>
Signed-off-by: Dan Carpenter <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Dan Carpenter authored and axboe committed Jun 20, 2018
1 parent a1e7918 commit ce042c1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions block/sed-opal.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
return 0;
}

if (n > resp->num) {
if (n >= resp->num) {
pr_debug("Response has %d tokens. Can't access %d\n",
resp->num, n);
return 0;
Expand Down Expand Up @@ -916,7 +916,7 @@ static u64 response_get_u64(const struct parsed_resp *resp, int n)
return 0;
}

if (n > resp->num) {
if (n >= resp->num) {
pr_debug("Response has %d tokens. Can't access %d\n",
resp->num, n);
return 0;
Expand Down

0 comments on commit ce042c1

Please sign in to comment.