Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5983324ybc; Wed, 27 Nov 2019 12:53:14 -0800 (PST) X-Google-Smtp-Source: APXvYqyoHpXHbC+QubQBm7VnpmjCNQUD2JYuXxgS4OSxOZbkHRvV29MY9XrtVLNM0MO5dozsW82e X-Received: by 2002:a17:906:c57:: with SMTP id t23mr51201415ejf.240.1574887994605; Wed, 27 Nov 2019 12:53:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887994; cv=none; d=google.com; s=arc-20160816; b=z3cRb+REX9XvOlQjKuPRwq6GYWspTCKsV1dg0KV0E9eDTqsys9OlTJD/ifT39J/4IO Ps8THYKBrfyaqcZg/phsaoUEYFF/N6qAqETUKuzDbkcHqga4dLwJXRODIW9TfzM2QX9S w2HK2DRK/Eh2VPiPhlB5aylP6kf5Zi8bXLOysEdHM/FzfrFasyMUS6TlSFacCw2Cc6Pb xOEXdwg6hpE7ao8TNfdKi2LSeNkDF0AnhDDOsRzR/qhMmLZals2Ozi03KzV/ajkIW9t8 C6ZydGJQDj1tpK3vaTRt8Lf4xoBZpkQP+CsEfox3nes37CAUxQzm0bElx4rjyRIxCT+6 Pw5g== 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=a6/tuaLp+/ATmCxfxFwFtka0tRal+5iw+/kSJ3kMEcpFnRSy5qwAsUAi+3rOzsAc8z 49U6LZpud7+jkO6gZzGPyqrqUw+ltKvPtw6w/jbvEco4xXlMN6abJh0XGc7lz5DavBAo OISRkG4pvczWQ2ZqsBwGcq4aRU/7C30m9qfqXBRVRDxT+iwuSPkWb1VYi/YnZLcEjpvV rd8RbWuRUy944rtpj5apO3srkMtKDI3otSrAU/V7FuQ0aHI+pghSaw53P/+qaV8unYUY xz8iy2zP2o1X3lpS5VipPoQazYszCH+rfyIZmt2ffa1oj+30k0GHipEKEtpuHf0LVzDQ /nfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qoivxwal; 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 q20si10050170eja.339.2019.11.27.12.52.50; Wed, 27 Nov 2019 12:53:14 -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=Qoivxwal; 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 S1730141AbfK0Usm (ORCPT + 99 others); Wed, 27 Nov 2019 15:48:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:33922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727739AbfK0Usf (ORCPT ); Wed, 27 Nov 2019 15:48:35 -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 DEA4C217C3; Wed, 27 Nov 2019 20:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887715; bh=KzaYq/ZxefBgTK1mWLIBUbunCDUrWNx+9I10MwP1UNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QoivxwalVsenqd1J+jWOhyPrb0ewTqZWgSkEwc5Ps+8ECcngdy5lxeF5Yc/kUfCO+ BevwHpK+dDQvOP7YSPQlY6ETYtVyv4mkx7Az9kSmKKwRXpIbbfhNe3MfZjMuEEMDvY UZ1bNk20FjkJuKG0G1Ha+79YQ93yvKQmD9ayD6OE= 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.14 066/211] usbip: tools: fix atoi() on non-null terminated string Date: Wed, 27 Nov 2019 21:29:59 +0100 Message-Id: <20191127203100.142713705@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@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