From patchwork Tue Jul 29 15:14:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4640781 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A5CEA9F32F for ; Tue, 29 Jul 2014 15:15:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 522F820115 for ; Tue, 29 Jul 2014 15:15:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7610F20145 for ; Tue, 29 Jul 2014 15:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753970AbaG2POx (ORCPT ); Tue, 29 Jul 2014 11:14:53 -0400 Received: from mail-wg0-f41.google.com ([74.125.82.41]:57620 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752764AbaG2POw (ORCPT ); Tue, 29 Jul 2014 11:14:52 -0400 Received: by mail-wg0-f41.google.com with SMTP id z12so9148821wgg.12 for ; Tue, 29 Jul 2014 08:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gowoR9rK3D3NRrVABcBV+YScGMyaeMuUDiS4NAlkE/Q=; b=vFHUJSirdvhe/GPyiLgDVSAKkjcp4Uqgm030Tajv02l4y1USIWZmIaubgpcvFczuCu kNSOOrC/zY4hAl4C3EJS2deYn25+pQhDIaxCiaAtw5LQSkHdx/zWh06WpppPXJiZiVVn MMdMS+uxdE/q7159sWbQB9XMs9iM87lRnsSfyylIPe2pK9NoQ0lKjqF8GNDL2dBo7oqR n+OgqUZLpxZmus7Sl5pmd6Wyzpoj0TyKVL0EX20rWgfBR/+uI/2bOiQMSOvAQZ+PT7FZ NaSGwCqws3j5qanMolygZCtLRwhoYmrPRrJQuFaC6jdCgpaW8rApCpj9X93/+1BQ5W16 DKHw== X-Received: by 10.194.92.244 with SMTP id cp20mr3823157wjb.135.1406646891371; Tue, 29 Jul 2014 08:14:51 -0700 (PDT) Received: from david-tp.localdomain (stgt-4d0247ad.pool.mediaWays.net. [77.2.71.173]) by mx.google.com with ESMTPSA id fs3sm44361822wic.20.2014.07.29.08.14.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Jul 2014 08:14:50 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , David Herrmann Subject: [PATCH 04/12] HID: uhid: avoid magic-numbers when setting strings Date: Tue, 29 Jul 2014 17:14:18 +0200 Message-Id: <1406646866-999-5-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.0.3 In-Reply-To: <1406646866-999-1-git-send-email-dh.herrmann@gmail.com> References: <1406646866-999-1-git-send-email-dh.herrmann@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 Avoid hard-coding the target buffer sizes and use sizeof() instead. This also makes us future-proof to buffer-extensions later on. Signed-off-by: David Herrmann --- drivers/hid/uhid.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index bf13746..5dee8bd 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c @@ -363,7 +363,7 @@ static int uhid_dev_create2(struct uhid_device *uhid, const struct uhid_event *ev) { struct hid_device *hid; - size_t rd_size; + size_t rd_size, len; void *rd_data; int ret; @@ -387,12 +387,12 @@ static int uhid_dev_create2(struct uhid_device *uhid, goto err_free; } - strncpy(hid->name, ev->u.create2.name, 127); - hid->name[127] = 0; - strncpy(hid->phys, ev->u.create2.phys, 63); - hid->phys[63] = 0; - strncpy(hid->uniq, ev->u.create2.uniq, 63); - hid->uniq[63] = 0; + len = min(sizeof(hid->name), sizeof(ev->u.create2.name)) - 1; + strncpy(hid->name, ev->u.create2.name, len); + len = min(sizeof(hid->phys), sizeof(ev->u.create2.phys)) - 1; + strncpy(hid->phys, ev->u.create2.phys, len); + len = min(sizeof(hid->uniq), sizeof(ev->u.create2.uniq)) - 1; + strncpy(hid->uniq, ev->u.create2.uniq, len); hid->ll_driver = &uhid_hid_driver; hid->bus = ev->u.create2.bus;