drm/modes: Fix unterminated strncpy
Subsystems (2)
PATCH v2 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]>
---
Changes in v2:
- Check whether mode_end + 1 exceeds
the size of mode->name.
drivers/gpu/drm/drm_modes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_modes.c +3 -1
@@ -1770,7 +1770,9 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, }if (named_mode) { -strncpy (mode->name, name, mode_end); +if (mode_end +1 >DRM_DISPLAY_MODE_LEN ) +return false; +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