Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce042c18 authored by Dan Carpenter's avatar Dan Carpenter Committed by Jens Axboe
Browse files

block: sed-opal: Fix a couple off by one bugs



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: 455a7b23 ("block: Add Sed-opal library")
Reviewed-by: default avatarScott Bauer <scott.bauer@intel.com>
Tested-by: default avatarScott Bauer <scott.bauer@intel.com>
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent a1e79188
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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;