Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3522282imu; Fri, 18 Jan 2019 11:53:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN7xpZw+VLaOIqXLTeh3JvA1P8fpu3p6cnEG+4sbv2e6pdgdJg7DpQwSAu7FfeJSJLvF4T0U X-Received: by 2002:a17:902:ac8f:: with SMTP id h15mr19890260plr.245.1547841221755; Fri, 18 Jan 2019 11:53:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547841221; cv=none; d=google.com; s=arc-20160816; b=esQOTq87LDO8GzSfrQ+rRy2SNBm/hRKH8Drz3gc+tqIATzcvWlT57Wp9CotghlsccO GmTuH/uW47GZRAX8Whyi3hLirio07AoLnYMrY3QyO5tjOEjLmkSzky8FNhJVGVM2QTin xDZI2qwkqiVaAX3Wt7vcbe6wjG2CiRZuh+VLOsL9vIQMIZNzSPQCbey+M7ctS03wTVdg c+22PFEs+/HaG8NyuKIjklnnmR2RFYvk0TkmNU9JDyl7Hd6eeRA17uJRhdZegohMZx7f ulDsVMpIpGubhu3dIY4GwFUZm12ECWbeyCiBXrkf2Ff880YoH/gIl/UpJetCEjfwORlx btNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=p3DLgNcFfQ095n16Yw0NK/AW+Rm6hsJLiO/1Wz0rQeo=; b=Rd90HoTpJGjumfQ40UzLQrMVQAkq15b4ZICectXf4I2DQyRDERWfAxmvZeXuE76Rer dDUBxIqa/4+NFf1+06dQGijsXVh4os9hlJHWk3mokP+5Z36bUM67tbDMDGCIpmyZF+d5 kl7/Fg60c8nmbvSy0QCrx5mShNvKNOGTXXMHVhqMnDjksXA/DlzW2maW8N1ZNBW0B1LR Um8rjOUMh8IJ/xGwjR9BRl4wzJY7sja7yPgRoI8sdggllcC3JzLssnL+Xfb2SQVsAHYD TB5puxQazTMD9GEnBesXJi76cWoDhGPNM58VzJxiAYXAB/o+wt2UwjMHDyoxj/cBHGjB ZQLA== 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 q14si5284568pgg.433.2019.01.18.11.53.26; Fri, 18 Jan 2019 11:53:41 -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 S1729319AbfARTvZ (ORCPT + 99 others); Fri, 18 Jan 2019 14:51:25 -0500 Received: from smtprelay0036.hostedemail.com ([216.40.44.36]:53759 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729206AbfARTvZ (ORCPT ); Fri, 18 Jan 2019 14:51:25 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 7E9E8181D341B; Fri, 18 Jan 2019 19:51:23 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 57,3.5,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:599:857:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2743:2828:3138:3139:3140:3141:3142:3353:3622:3865:3867:3868:3871:3872:3873:4250:4321:5007:6119:7903:8603:8879:10013:10400:10848:11026:11232:11473:11658:11914:12043:12114:12438:12740:12760:12895:13069:13255:13311:13357:13439:14659:14721:21080:21092:21451:21627:21773:30003:30012:30025:30054:30070:30079:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:1:0,LFtime:28,LUA_SUMMARY:none X-HE-Tag: ball94_c0277c79591b X-Filterd-Recvd-Size: 2645 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA; Fri, 18 Jan 2019 19:51:22 +0000 (UTC) Message-ID: Subject: Re: [PATCH] video/hdmi: Change strncpy() into memcpy() in hdmi_spd_infoframe_init From: Joe Perches To: Mathieu Malaterre , Bartlomiej Zolnierkiewicz Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 18 Jan 2019 11:51:20 -0800 In-Reply-To: <20190118193248.535-1-malat@debian.org> References: <20190118193248.535-1-malat@debian.org> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. You probably want strscpy. 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]; 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-};