Commit 1d0e4829 authored by Gabriel Ravier's avatar Gabriel Ravier Committed by Greg Kroah-Hartman

tools: gpio-hammer: Avoid potential overflow in main

[ Upstream commit d1ee7e1f ]

If '-o' was used more than 64 times in a single invocation of gpio-hammer,
this could lead to an overflow of the 'lines' array. This commit fixes
this by avoiding the overflow and giving a proper diagnostic back to the
user
Signed-off-by: default avatarGabriel Ravier <gabravier@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 68aaf039
......@@ -138,7 +138,14 @@ int main(int argc, char **argv)
device_name = optarg;
break;
case 'o':
lines[i] = strtoul(optarg, NULL, 10);
/*
* Avoid overflow. Do not immediately error, we want to
* be able to accurately report on the amount of times
* '-o' was given to give an accurate error message
*/
if (i < GPIOHANDLES_MAX)
lines[i] = strtoul(optarg, NULL, 10);
i++;
break;
case '?':
......@@ -146,6 +153,14 @@ int main(int argc, char **argv)
return -1;
}
}
if (i >= GPIOHANDLES_MAX) {
fprintf(stderr,
"Only %d occurences of '-o' are allowed, %d were found\n",
GPIOHANDLES_MAX, i + 1);
return -1;
}
nlines = i;
if (!device_name || !nlines) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment