drm/modes: Fix unterminated strncpy
Subsystems (2)
PATCH 1/1 drm/modes: Fix unterminated strncpy
strncpy(dest, src, strlen(src)) leads to unterminated dest, which is dangerous.
Fix it by using strscpy.
Signed-off-by Chuhong Yuan <[email protected]>
--- drivers/gpu/drm/drm_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_modes.c +1 -1
@@ -1770,7 +1770,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, }if (named_mode) { -strncpy (mode->name, name, mode_end); +strscpy (mode->name, name, mode_end +1 ); }else { ret = drm_mode_parse_cmdline_res_mode(name, mode_end, parse_extras,
Signature · 1 line
2.20.1
Quoted 14 lines · Chuhong Yuan
strncpy(dest, src, strlen(src))leads to unterminated dest, which is dangerous.
Fix it by using strscpy.Signed-off-by Chuhong Yuan <[email protected]>--- drivers/gpu/drm/drm_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/drm_modes.c +0
-0
drivers/gpu/drm/drm_modes.c bool drm_mode_parse_command_line_for_connector(const char *mode_option, · line 1773
Quoted 5 lines
drivers/gpu/drm/drm_modes.c +1
-1@@ -1770,7 +1770,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, }if (named_mode) { -strncpy (mode->name, name, mode_end); +strscpy (mode->name, name, mode_end +1 );
Shouldn't you be checking that mode_end + 1 is not > than the size of mode->name (ie: DRM_DISPLAY_MODE_LEN)? This still seems unsafe.
Sean
Quoted 6 lines
drivers/gpu/drm/drm_modes.c +0
-0}else { ret = drm_mode_parse_cmdline_res_mode(name, mode_end, parse_extras,Signature · 1 line
2.20.1
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS