From patchwork Thu Dec 11 12:51:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 5475921 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 953259F1CD for ; Thu, 11 Dec 2014 12:53:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD74A200E0 for ; Thu, 11 Dec 2014 12:53:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9D60200CA for ; Thu, 11 Dec 2014 12:53:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932470AbaLKMw5 (ORCPT ); Thu, 11 Dec 2014 07:52:57 -0500 Received: from lekensteyn.nl ([178.21.112.251]:41206 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932637AbaLKMve (ORCPT ); Thu, 11 Dec 2014 07:51:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2014-q3; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=D8l3pfxHEhI2N+EssUhRzfJRasE/O7XKgoCK04IrvsI=; b=TSJE3wRT0E9WW1RL7h6JONktd9Dicir9VKWAh/hOKpzDBw8bTe7J4adEgdVX5ddQgGNsHLCFHUtL7e5mwRdR5ixMWFaS3AlyU5JKUNeppNvvO2kgXFZajf2TAU3o2TknirBMLmSUTlroqfkchCVgQuJ3+sF0rTb7CtdKtF1WYCNiCII7iHupaHVAE5dPTiZ35W0Fi/XsOWk9qrBaGXRXtfp55vOScJVNq8efC6q5XewPxK013Jt4Md+0cZAVYYvdxr7zCb3WS54KpPrya+0bLB66PaWhqA7lRB2XcWWpFi5VbUiIsBHWs4TrjVbIPaGn3fPCN4gLkxBOnD88RR71LA==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1Xz3DH-00020h-B4; Thu, 11 Dec 2014 13:51:23 +0100 From: Peter Wu To: Benjamin Tissoires , Jiri Kosina , Nestor Lopez Casado Cc: Peter Hutterer , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] HID: logitech-hidpp: check name retrieval return code Date: Thu, 11 Dec 2014 13:51:18 +0100 Message-Id: <1418302280-14794-3-git-send-email-peter@lekensteyn.nl> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418302280-14794-1-git-send-email-peter@lekensteyn.nl> References: <1418302280-14794-1-git-send-email-peter@lekensteyn.nl> X-Spam-Score: -0.0 (/) X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP hidpp_devicenametype_get_device_name() may return a negative value on protocol errors (for example, when the device is powered off). Explicitly check this condition to avoid a long-running loop. (0 cannot be returned as __name_length - index > 0, but check for it anyway as it would otherwise result in an infinite loop.) Signed-off-by: Peter Wu Reviewed-by: Benjamin Tissoires --- drivers/hid/hid-logitech-hidpp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 5066df8..4d72c20 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -484,10 +484,16 @@ static char *hidpp_get_device_name(struct hidpp_device *hidpp) if (!name) return NULL; - while (index < __name_length) - index += hidpp_devicenametype_get_device_name(hidpp, + while (index < __name_length) { + ret = hidpp_devicenametype_get_device_name(hidpp, feature_index, index, name + index, __name_length - index); + if (ret <= 0) { + kfree(name); + return NULL; + } + index += ret; + } return name; }