]> git.baikalelectronics.ru Git - kernel.git/commit
drm/amd/display: Fix overflow/truncation from strncpy.
authorNicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Fri, 20 Jul 2018 14:17:29 +0000 (10:17 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 4 Dec 2018 20:01:56 +0000 (15:01 -0500)
commit31cb28e603bed8e65ab1b2aec52ddc1c2661d0e0
treef1d10cf7a23b58f653de878494f565b7255deb15
parent4f9d99c163d5a0859a5ac45748a9652fcf1aee8b
drm/amd/display: Fix overflow/truncation from strncpy.

[Why]

New GCC warnings for stringop-truncation and stringop-overflow help
catch common misuse of strncpy. This patch suppresses these warnings
by fixing bugs identified by them.

[How]

Since the parameter passed for name in amdpgu_dm_create_common_mode has
no fixed length, if the string is >= DRM_DISPLAY_MODE_LEN then
mode->name will not be null-terminated.

The truncation in fill_audio_info won't actually occur (and the string
will be null-terminated since the buffer is initialized to zero), but
the warning can be suppressed by using the proper buffer size.

This patch fixes both issues by using the real size for the buffer and
making use of strscpy (which always terminates).

Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c