Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3540477imu; Fri, 18 Jan 2019 12:11:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN7PZ3hwoQYQ7Ky9FnONxlE6u+/XtUBK1fWtYhJ48AKEMDQ2LyNrSb8rL5+UvXSJ5UpsoVvR X-Received: by 2002:a63:6906:: with SMTP id e6mr18781564pgc.144.1547842305968; Fri, 18 Jan 2019 12:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547842305; cv=none; d=google.com; s=arc-20160816; b=l7TWg4s5hTc5602K3EGnKxIQE9WZMsvmlWv53gppMMBRnoKRrAJDu6gf7LnN0c2EbS 0pK9EinMEpt6QJU26BC39aZOOW1d/vNeoHnnuSLHFzKORc10Pldre33wbmxalFwAymNl KuMYPGl4lfmemz1AuYaz7T579z7EFouTOK6Qcp2eIOJJgH7VdFaY2lkN2a7ecZU7zKij uwYcFmpGbAQ6P/7gTNt4fHCB+h48Cw6td0vnJyOEYEsLW4TZWPYpFwBwgUaXTIbyWBn4 TO1HqUg+uLVTRAKhMfskvyGYow4batij5Iyta7R+f+4LwAAOrZeoXy6ubomXoVVgAmMf iOqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=+sUo+0azJHeU/IxduQC2o8S5A/gjk7NSQ/GRq57LSFQ=; b=pmBuHFyxzchxQIARLfoPa6i+x6qTtq5rYcdTmtVvWPe20mK6wgJKq7qxH5GHRH80cA wiRkk/ZuPPeJBlKx0wdSy3QNIGqloGJDWJ7SYoZi0zV/8yMBvBUmlReXyeLKaKgE3mpY kIvpvhGHtOS91Q6eIqlPcwYGqMHF22EsevovvwYg3DtXnFXpiU95AzKHmPbn40vCjKrw dne7APZLhZLZtwk74xNTnAA4QvfdvTD9Llj0My9Z+8L1axMrRElchn0KiXPp+AiLogoM /Nv2ZV3Zxmdt4YqZsVS1qp6RRzJJeWmf4aupvo8SVqoE2AAjNhAt8G8qQhmQDqFNHa4L j7Ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ca6si5534781plb.141.2019.01.18.12.11.30; Fri, 18 Jan 2019 12:11:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729439AbfARUKL (ORCPT + 99 others); Fri, 18 Jan 2019 15:10:11 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:44415 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729356AbfARUKK (ORCPT ); Fri, 18 Jan 2019 15:10:10 -0500 Received: by mail-ot1-f68.google.com with SMTP id f18so15463055otl.11; Fri, 18 Jan 2019 12:10:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+sUo+0azJHeU/IxduQC2o8S5A/gjk7NSQ/GRq57LSFQ=; b=tcIWXtySnWzY8r5wNWSZlTOYkV0RkWCBFBjD1YliMgYbYPTXxQWS1TUehJKp8Intz7 nQn/wflNHmF2ifirmMJxx7i56Y6/MlmYDEo2T3FpMv6S/UGT3cPU3zLtRwEPrrCmUAE3 2JwPwjJDn5vNXjBcECskhh1EfAdRDcK9mgBXjN3oRwHQiEkDQVnQ+onfKLXu6EPlRUkS oGmLE13rqkcn2FRotrWgflcxFcuotg2p7yo1Ig8XgvXNWtPwvxGXV5EMap416z/JGA0x tpO042uuYCOb9Z7Y21Ca0LvX6ylrs3MUNT5aYAotvx2kHhykdDmmIimJe+emxgUohrC4 tghQ== X-Gm-Message-State: AJcUukfK1w2eQDbdGrAWEyzY4M5/M37WsCtvwax/qQcfwG2GvzR6sxLk RGkaHhkDRbdzxzLEB9ohDEh+l9HcApwGK1fuiwR5+ikj X-Received: by 2002:a9d:3d24:: with SMTP id a33mr12924903otc.365.1547842209857; Fri, 18 Jan 2019 12:10:09 -0800 (PST) MIME-Version: 1.0 References: <20190118193248.535-1-malat@debian.org> In-Reply-To: From: Mathieu Malaterre Date: Fri, 18 Jan 2019 21:09:58 +0100 Message-ID: Subject: Re: [PATCH] video/hdmi: Change strncpy() into memcpy() in hdmi_spd_infoframe_init To: Joe Perches Cc: Bartlomiej Zolnierkiewicz , dri-devel , Linux Fbdev development list , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 18, 2019 at 8:51 PM Joe Perches wrote: > > On Fri, 2019-01-18 at 20:32 +0100, Mathieu Malaterre wrote: > > Using strncpy() is less than perfect since the destination buffers do not > > need to be NUL terminated. Replace strncpy() with memcpy() to address a > > warning triggered by gcc using W=1 and optimize the code a bit. > > > > This commit removes the following warnings: > > > > drivers/video/hdmi.c:234:2: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation] > > drivers/video/hdmi.c:235:2: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation] > [] > > diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c > [] > > @@ -231,8 +231,8 @@ int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame, > > frame->version = 1; > > frame->length = HDMI_SPD_INFOFRAME_SIZE; > > > > - strncpy(frame->vendor, vendor, sizeof(frame->vendor)); > > - strncpy(frame->product, product, sizeof(frame->product)); > > + memcpy(frame->vendor, vendor, sizeof(frame->vendor)); > > + memcpy(frame->product, product, sizeof(frame->product)); > > This is not good. > > vendor can be any location and shorter than sizeof(frame->vendor) > so this can copy from invalid memory locations. Ah right. I did not realize that and know I see the call with "Intel", will re-spin. > You probably want strscpy. Right. > This is called with at least "mediatek" and "broadcom", so perhaps > it's better still to change the struct vendor size to something a > bit larger. Maybe change vendor[8] to vendor[16]; Looks like 8 bytes is required for call like hdmi_spd_infoframe_unpack() > include/linux/hdmi.h:struct hdmi_spd_infoframe { > include/linux/hdmi.h- enum hdmi_infoframe_type type; > include/linux/hdmi.h- unsigned char version; > include/linux/hdmi.h- unsigned char length; > include/linux/hdmi.h- char vendor[8]; > include/linux/hdmi.h- char product[16]; > include/linux/hdmi.h- enum hdmi_spd_sdi sdi; > include/linux/hdmi.h-}; > >