[PATCH libdrm 2/3] xf86drm: add buffer size safety to sprintf()

Emil Velikov emil.l.velikov at gmail.com
Mon Mar 26 14:02:19 UTC 2018


On 26 March 2018 at 11:26, Eric Engestrom <eric.engestrom at imgtec.com> wrote:
> Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
> ---
>  xf86drm.c     | 6 +++---
>  xf86drmMode.c | 6 ++++--
>  2 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index b6e5d8cc1bb50ffe75a2..5701952ae83634b47628 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -349,7 +349,7 @@ static int drmOpenDevice(dev_t dev, int minor, int type)
>          return -EINVAL;
>      };
>
> -    sprintf(buf, dev_name, DRM_DIR_NAME, minor);
> +    snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, minor);
The patch feels a big meh, for two reasons:
 - buffer contents are controlled and will never overflow
 - s{n,}printf return value is not checked

If there's a particular tool that should be silenced up sure, let's
land it. Otherwise I might as well list my 'grand master plan', we can
start deleting all this code ;-)

What do you think?
Emil


More information about the dri-devel mailing list