Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5975915ybc; Wed, 27 Nov 2019 12:43:58 -0800 (PST) X-Google-Smtp-Source: APXvYqwMZPHlIBqqmzp5KUp+6eMu6SyFmd+OkByRQ4L0hEUNLnAq3e1vHmaur7M2qnDevYPURQlY X-Received: by 2002:a50:ec97:: with SMTP id e23mr34302886edr.111.1574887438240; Wed, 27 Nov 2019 12:43:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887438; cv=none; d=google.com; s=arc-20160816; b=SlvoFxFMXMVTyoyGlJ/j8qwEHBo5MaEvOHsIyPSGmGr5i/eEym1Lexh+I0ov7B09Bs uW2WRPleyvhPhHMmbcgIiKPporcxpTOjvZrlQxX8LNx3O76b772PkYRVL3si7uZHiHxd Y/qrXp6fhIgTOrxQRoT/uS3zbHOmd3fxM//5QNLQjLiESPAJYLzJLJXSGjMsPwfPVym/ Er808lt64Lr4viQDO6ygajTKlYoPNLpRUMklEcpWsuXVwyhViPYHzwYTJ856fEt2hppB SXmdLPKYw8tzKljP9v7KO9PCXWYDUmbPp9Bl2cEJ50XCojgdn5Iqi1ucLsaf+tuTBU+k nFpg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=nGuwAGjmmwMEVgBbf7siuMactHjMahQcIbbgraeDI+A=; b=jm8tckm6D8nOdHjKMryOBMWjAYj+44nTm+dOUQpvKfbxlihx2wPQ6EU0M9d71+RHVv SZweyvjRGjMsrUHTodFBHLl1f0FUeIcWlMLJNufqlT+qDLgMDLtf5oywgwWZtjI+kMDp FlssneNI45yCA0fh7qMNt2EsX++N/+K/ImN/oo7cq7mxD4NzEUQkkRehS2M3a2pjeR+A nP0b77NGO7L042rOvXp6eO0m5XgRX0Kmn6dgfQIJqc0myG9RcQ74bLJq2laJI99qrnQ0 uYI0zTHSvpp9Ie+Xz5y0uUJsoazgpdutGrGD5DfhpBYqlo1gdXvfzYBUAEXKquPiiGhA Do/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DTegwJmC; 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 t18si10278735ejx.354.2019.11.27.12.43.34; Wed, 27 Nov 2019 12:43:58 -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; dkim=pass header.i=@kernel.org header.s=default header.b=DTegwJmC; 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 S1729136AbfK0UlI (ORCPT + 99 others); Wed, 27 Nov 2019 15:41:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:46082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbfK0UlG (ORCPT ); Wed, 27 Nov 2019 15:41:06 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CFC4B21774; Wed, 27 Nov 2019 20:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887266; bh=KzaYq/ZxefBgTK1mWLIBUbunCDUrWNx+9I10MwP1UNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTegwJmCsO+9cHgsw7k4Q23TxEWJxRWOx1GMx1sJoq7exy3OolIeXANOfzCb8pdAg 8II74UbRAS7zseznDQfJHn0fsCqxXtW8rm1AYw79NUxboVygB1nTa/y46it98+v/3c TmvoYsK3DnWFfGcxymdSJOR4aCTj1E/4s6TXHF/A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Sasha Levin Subject: [PATCH 4.9 044/151] usbip: tools: fix atoi() on non-null terminated string Date: Wed, 27 Nov 2019 21:30:27 +0100 Message-Id: <20191127203027.542833130@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203000.773542911@linuxfoundation.org> References: <20191127203000.773542911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit e325808c0051b16729ffd472ff887c6cae5c6317 ] Currently the call to atoi is being passed a single char string that is not null terminated, so there is a potential read overrun along the stack when parsing for an integer value. Fix this by instead using a 2 char string that is initialized to all zeros to ensure that a 1 char read into the string is always terminated with a \0. Detected by cppcheck: "Invalid atoi() argument nr 1. A nul-terminated string is required." Fixes: 3391ba0e2792 ("usbip: tools: Extract generic code to be shared with vudc backend") Signed-off-by: Colin Ian King Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- tools/usb/usbip/libsrc/usbip_host_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c index 6ff7b601f8545..f5ad219a324e8 100644 --- a/tools/usb/usbip/libsrc/usbip_host_common.c +++ b/tools/usb/usbip/libsrc/usbip_host_common.c @@ -43,7 +43,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev) int size; int fd; int length; - char status; + char status[2] = { 0 }; int value = 0; size = snprintf(status_attr_path, sizeof(status_attr_path), @@ -61,14 +61,14 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev) return -1; } - length = read(fd, &status, 1); + length = read(fd, status, 1); if (length < 0) { err("error reading attribute %s", status_attr_path); close(fd); return -1; } - value = atoi(&status); + value = atoi(status); return value; } -- 2.20.1