Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6018261ybc; Wed, 27 Nov 2019 13:30:08 -0800 (PST) X-Google-Smtp-Source: APXvYqx0AVLW3+yAOJOOmiXxwwlfjJb73mFH+mfWxrKA2O+V60lwD6NEJAYhQnTxdh6qhiwLKNXa X-Received: by 2002:aa7:c402:: with SMTP id j2mr15433679edq.249.1574890208262; Wed, 27 Nov 2019 13:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890208; cv=none; d=google.com; s=arc-20160816; b=rb6dRAHHQGpeiu3Dyix/pX0qQar4WIY0FNV7N2nYJ4rZbNp1CyQ4Y2ZEfR8w3qrVHR Wf3+gC32T8rqu94bT40cq6IOKtRUHw2jlcUz7+dYT4TTtMQYkIsKMkYEGVB4z5cc5FxS m99LIM0CXaNYXN1nTX69o2DC7Ern/TEfExXrSprkV7Aok5i5NMQbtGToaWbMHHOu9xfE cNLZxelF2krDZipaTP9qyiRWa0G0PZGG9FAQXqDYBl2C27wtcCiZZ1PQrocbQ0HMEHsm mumAaNkSzlrsoNoAOcS+r98Kv1XiuNlnU18ct3f7aBj3X8O8XT39uU5I7WkCFrH4f3uJ DYVg== 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=aaWLaB2UxOV4hRFkVYvR9mwOVTbXSop2reKwLlx3lw8=; b=LlCBz7udk2ni6S9fQqvrHg9S0y+ZafOYLQeyU13iJyechi1NLiEmqxzPCsnI1/H7B7 53IJJ9fD72LmRfdD60Zr+leST5GH5kNagJ4VR56WWN/W0ZPLD8g71fGO2ssgnB+Y7qw3 zRzSaA1scUeTmmx+D7/j7Yurxx208TLXhENjP9g6tM4T7r3IDC/M3xm+G+d3ktrHUiEg xXoz+KHMHGSjNJvxWO2YTcyujQWUdyswFnp3nnVqA9AmapGDk38OszKzYAy1mZpeoSo2 SOhoTMRSg7JxipeopE8LUsxkwRFSSWViwmOrx7ByusMiwp7y2SpUH+0G6W4XIyJ2o2Ce FV7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1ac2CNvS; 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 y14si11058356edu.250.2019.11.27.13.29.44; Wed, 27 Nov 2019 13:30:08 -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=1ac2CNvS; 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 S1731420AbfK0U72 (ORCPT + 99 others); Wed, 27 Nov 2019 15:59:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:50834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731404AbfK0U7W (ORCPT ); Wed, 27 Nov 2019 15:59:22 -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 6494620678; Wed, 27 Nov 2019 20:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888360; bh=xOiN5LjMgBp//ENnSVzIBfa6sOV/4n1mY+so8re9zjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ac2CNvSkbgTgYPiTX/AFuW6p8UYkwfnpWO8cIWntcBgIlclg/YPGBev0RnWrmOoZ 1fpiOxAJGo/JSz7h1CU4hwGRndl1wwlA8SGzBOIiW7PIePpBnJ6JjrUUdEu+kansgg dILlfGKvRnrQVSVwVVTKAOUoj9HGP6PW0HZCcG0Y= 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.19 097/306] usbip: tools: fix atoi() on non-null terminated string Date: Wed, 27 Nov 2019 21:29:07 +0100 Message-Id: <20191127203121.975683825@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 dc93fadbee963..d79c7581b175f 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