2019-01-08 14:08:53

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH] dio: Fix buffer overflow in case of unknown board

With gcc 8.2.0:

drivers/dio/dio.c: In function ‘dio_init’:
drivers/dio/dio.c:240:17: warning: ‘strcpy’ writing 69 or more bytes into a region of size 64 overflows the destination [-Wstringop-overflow=]
strcpy(dev->name,dio_getname(dev->id));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Indeed, if an unknown board is present, the target buffer will overflow.
Shorten the unknown board name string to fix this.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
drivers/dio/dio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
index 92e78d16b476550c..4ff65c690b04b50b 100644
--- a/drivers/dio/dio.c
+++ b/drivers/dio/dio.c
@@ -90,7 +90,7 @@ static struct dioname names[] =
#undef DIOFBNAME

static const char *unknowndioname
- = "unknown DIO board -- please email <[email protected]>!";
+ = "unknown DIO board, please email [email protected]";

static const char *dio_getname(int id)
{
--
2.17.1



2019-01-08 14:21:21

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] dio: Fix buffer overflow in case of unknown board

On Jan 08 2019, Geert Uytterhoeven <[email protected]> wrote:

> @@ -90,7 +90,7 @@ static struct dioname names[] =
> #undef DIOFBNAME
>
> static const char *unknowndioname
> - = "unknown DIO board -- please email <[email protected]>!";
> + = "unknown DIO board, please email [email protected]";

This could be declared as an array.

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."