Skip to contentSkip to conversation

video: fbdev: via: refactor deprecated strcpy

PATCH Superseded Ajith P V 2 participants 2 messages Aug 10 – Aug 13

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ajith P V

author
#0 lore raw

PATCH 1/1 video: fbdev: via: refactor deprecated strcpy

Replace the deprecated and unbounded strcpy() function with the safer strscpy() alternative when setting up the framebuffer fixed screen information [1][2].

The destination buffer fix->id is a fixed-size character array of 16 bytes. The source viafb_name is currently a static global string literal ("Via"), which safely fits the destination and poses no active overflow risk.

However, replacing strcpy() with strscpy() aligns this driver with the ongoing kernel-wide security initiative to eliminate unbounded string copies, hardening the code against future modifications.

This is a proactive API cleanup and there is no functional performance or truncation risk since viafb_name safely fits inside the 16-byte struct constraints.

---
 drivers/video/fbdev/via/viafbdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/via/viafbdev.c +1 -1
index 80f95dac32c8..925b56830fdd 100644
@@ -144,7 +144,7 @@ static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
 	struct viafb_par *viaparinfo)
 {
 	memset(fix, 0, sizeof(struct fb_fix_screeninfo));
-	strcpy(fix->id, viafb_name);
+	strscpy(fix->id, viafb_name, sizeof(fix->id));
 
 	fix->smem_start = viaparinfo->fbmem;
 	fix->smem_len = viaparinfo->fbmem_free;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · Ajith P V

Replace the deprecated and unbounded strcpy() function with the safer strscpy() alternative when setting up the framebuffer fixed screen information [1][2].

The destination buffer fix->id is a fixed-size character array of 16 bytes. The source viafb_name is currently a static global string literal ("Via"), which safely fits the destination and poses no active overflow risk.

correct.

Quoted 3 lines

However, replacing strcpy() with strscpy() aligns this driver with the ongoing kernel-wide security initiative to eliminate unbounded string copies, hardening the code against future modifications.

Compilers often can optimize strcpy() but not strscpy().
So, why not simply dropping viafb_name and replace it with a constant string? Or even make it 'const char viafb_name[] = "viafb";' and use this? Then the compiler can detect any issues at compile time.

Helge