From patchwork Tue Mar 8 20:40:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 8537661 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 73E249F372 for ; Tue, 8 Mar 2016 20:42:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3B0D20131 for ; Tue, 8 Mar 2016 20:42:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C05382011D for ; Tue, 8 Mar 2016 20:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbcCHUl3 (ORCPT ); Tue, 8 Mar 2016 15:41:29 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:36192 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751724AbcCHUlK (ORCPT ); Tue, 8 Mar 2016 15:41:10 -0500 Received: by mail-wm0-f44.google.com with SMTP id n186so149581355wmn.1 for ; Tue, 08 Mar 2016 12:41:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J8wdIF3w6LBbVPGWkBkjc6CR6JV13yzzpE7rlj0G19E=; b=DQlekRn5q7/VozthqJheqxTE8X1GtDK594d7UR5QLwoldskB6LqwaCYMTI3WoHSnZz kG2ozHrcU33nUG122R0J/BD9b9cCmGFYdbF+yRZpQWIQh27+8hcVmdfx5UOVcwZD9pSA 9VLZVQd1av13c+ZRccu4kR4Nf7DLAXN6KpmE4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J8wdIF3w6LBbVPGWkBkjc6CR6JV13yzzpE7rlj0G19E=; b=aNdOVhcRmjx4fDI/b+KDrI7l9pmIjy+q0D1QPucDxZHhxBgU0lol0j/025Cys6UKi0 Q61dEQR520npBqWGTu9lpKQ+6ZLP3Be/Acv3m6hTltHD6sLBJ5eyBeEWk7NkiI72VJqJ ozfIQX0QLHGC2IAjUHCPQs/w97zl7LU56APtUYXkFetCgni7voNJb0hW5zTxVn4Ym/o2 jHNyodS+AdTn6PD6QVJ7xOzBVK2/bkFrXjr2LM80woAVQzRPF88o1GiXyoLnOJ8n5vh9 E49D/lkAkbo4ZNlqitzNcOeilEhx/gal2pHdTfpMEDpy8IEBjEHlgcuP8j4OQGXm7s78 3F1A== X-Gm-Message-State: AD7BkJL4xmgn/ovOfg6x9XozUpAp1yQQlZnFd6sjxqmxesWZKqjGcMRkaxsaeEeY/m7kBQ== X-Received: by 10.194.91.205 with SMTP id cg13mr30441608wjb.166.1457469668850; Tue, 08 Mar 2016 12:41:08 -0800 (PST) Received: from wildmoose.dk (lvps87-230-87-209.dedicated.hosteurope.de. [87.230.87.209]) by smtp.gmail.com with ESMTPSA id b203sm5088471wmh.8.2016.03.08.12.41.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 12:41:08 -0800 (PST) From: Rasmus Villemoes To: Kees Cook , Andrew Morton , Mauro Carvalho Chehab Cc: Rasmus Villemoes , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC 6/7] [media] ati_remote: avoid fragile snprintf use Date: Tue, 8 Mar 2016 21:40:53 +0100 Message-Id: <1457469654-17059-7-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457469654-17059-1-git-send-email-linux@rasmusvillemoes.dk> References: <1457469654-17059-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Passing overlapping source and destination to snprintf is fragile. Replace with a single (mostly) equivalent call. If one wants to preserve the space preceding udev->product whether or not there was a manufacturer, just remove udev->manufacturer from the && expression. Signed-off-by: Rasmus Villemoes --- drivers/media/rc/ati_remote.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/media/rc/ati_remote.c b/drivers/media/rc/ati_remote.c index a35631891cc0..b6d367ba128a 100644 --- a/drivers/media/rc/ati_remote.c +++ b/drivers/media/rc/ati_remote.c @@ -866,13 +866,10 @@ static int ati_remote_probe(struct usb_interface *interface, strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys)); strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys)); - if (udev->manufacturer) - strlcpy(ati_remote->rc_name, udev->manufacturer, - sizeof(ati_remote->rc_name)); - - if (udev->product) - snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), - "%s %s", ati_remote->rc_name, udev->product); + snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), "%s%s%s", + udev->manufacturer ?: "", + udev->manufacturer && udev->product ? " " : "", + udev->product ?: ""); if (!strlen(ati_remote->rc_name)) snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),