Skip to contentSkip to conversation

dio: Fix buffer overflow in case of unknown board

PATCH Applied Geert Uytterhoeven 1 participant 2 messages Jan 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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, and declare it as an array while at it.

---
v2:
- Declare unknowndioname as an array.

---
 drivers/dio/dio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dio/dio.c +2 -2
index 92e78d16b476550c..c9aa15fb86a9aed0 100644
@@ -89,8 +89,8 @@ static struct dioname names[] =
 #undef DIONAME
 #undef DIOFBNAME
 
-static const char *unknowndioname 
-        = "unknown DIO board -- please email <[email protected]>!";
+static const char unknowndioname[]
+	= "unknown DIO board, please email [email protected]";
 
 static const char *dio_getname(int id)
 {
Signature · 1 line
2.17.1
author Applied
#1 lore raw
Quoted 7 lines · Geert Uytterhoeven

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));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 5 lines

Indeed, if an unknown board is present, the target buffer will overflow. Shorten the unknown board name string to fix this, and declare it as an array while at it.

Thanks, applied and queued for v5.1.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds