* [PATCH] drm/modes: Fix unterminated strncpy
@ 2019-07-30 8:40 Chuhong Yuan
2019-07-30 17:12 ` Sean Paul
0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-07-30 8:40 UTC (permalink / raw)
Cc: Maarten Lankhorst, Maxime Ripard, Sean Paul, David Airlie,
Daniel Vetter, dri-devel, linux-kernel, Chuhong Yuan
strncpy(dest, src, strlen(src)) leads to unterminated
dest, which is dangerous.
Fix it by using strscpy.
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
drivers/gpu/drm/drm_modes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 80fcd5dc1558..170fc24e0f31 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -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,
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/modes: Fix unterminated strncpy
2019-07-30 8:40 [PATCH] drm/modes: Fix unterminated strncpy Chuhong Yuan
@ 2019-07-30 17:12 ` Sean Paul
0 siblings, 0 replies; 2+ messages in thread
From: Sean Paul @ 2019-07-30 17:12 UTC (permalink / raw)
To: Chuhong Yuan
Cc: Maarten Lankhorst, Maxime Ripard, Sean Paul, David Airlie,
Daniel Vetter, dri-devel, linux-kernel
On Tue, Jul 30, 2019 at 04:40:32PM +0800, Chuhong Yuan wrote:
> strncpy(dest, src, strlen(src)) leads to unterminated
> dest, which is dangerous.
> Fix it by using strscpy.
>
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> drivers/gpu/drm/drm_modes.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index 80fcd5dc1558..170fc24e0f31 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -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
> } else {
> ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
> parse_extras,
> --
> 2.20.1
>
--
Sean Paul, Software Engineer, Google / Chromium OS
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-30 17:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30 8:40 [PATCH] drm/modes: Fix unterminated strncpy Chuhong Yuan
2019-07-30 17:12 ` Sean Paul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).