Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp775262ybc; Sat, 16 Nov 2019 08:28:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwPBtw1SyyeMVXMMyP2J+IHnscl2oVnfmve9nfzQRIGrYrWgIYwZyZ/jLtTeMu9aCQVMDZK X-Received: by 2002:adf:ec89:: with SMTP id z9mr21072471wrn.153.1573921708384; Sat, 16 Nov 2019 08:28:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921708; cv=none; d=google.com; s=arc-20160816; b=m3TNqHSI7Gag5nOOiiOEsQrhygFY4mz2RXfcHvm0cqsH3YwOnEZYKJ6SK963bQeZY3 6j7K5jPUpPfnC19KKL3htjgK/GDHaqyw8rx2kLQQic2z4k1ppSmG9uXLc+hCvMFlISI5 c4SRrA7PBn9ylfRI94dNh32oDvGK8vRIT+Qm/K8RKlouUt+bdRaJZDKkJr+X8SNTaNCk H6KhhmAfbuMtAgR36iOkHrR6AJAM2V7oMRiEz5TqfyDB8aabWRU+FcG1HA8mejGQL4pj GSmZ03Vwc80v2ae5hEDEslOLgNCjBXCLiV1q5JQlSmg5dQ+kbpw7Q3L087zk99TuDhj9 VUlw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aaWLaB2UxOV4hRFkVYvR9mwOVTbXSop2reKwLlx3lw8=; b=xSFjN8fKwGGkdjRwrgSjA9kBeTZJHmaIRSKMB8XTo9Zed+ciOhsPu764GZRKcldgxk TAzDlxzxgFAI1nDTDcHHuNNXLYc3bs8QNjGTG0NFUrhmlZN8aKgIyPRqdZGZIMv/bdT7 O6Vb9ff+RDpUwri6ucOqX7kYtdqbi2HCwLfLa5lEXnMzDJws428GORhlRhly8LwQAnsQ WN9anbRXkx5tbgsfDMM4923PgLcz6036TanbPwe/JFfofLyp6hjGhNr9N3unPQHS3ZcF YbQ1E9jKctvSFvBGAsPLftQY7D85JE8BdwgfxqvoxLQgB0BS3WtCuHkQgPKD+R5h3c04 J5uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E8zArXVs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si9173719edj.395.2019.11.16.08.28.02; Sat, 16 Nov 2019 08:28:28 -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=E8zArXVs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728480AbfKPPmu (ORCPT + 99 others); Sat, 16 Nov 2019 10:42:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:46484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728406AbfKPPmn (ORCPT ); Sat, 16 Nov 2019 10:42:43 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6794620740; Sat, 16 Nov 2019 15:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918962; bh=xOiN5LjMgBp//ENnSVzIBfa6sOV/4n1mY+so8re9zjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8zArXVsmtluBE6PoR6z8IFFe5pSFkWwSUJWoyCRV5uzajvoq42KGrML3f8dE60n5 OJVgQnTN3c2+TlrvbVmhzJMEGAAK0tDtBtO+glwj5s8W+pe9LIZea1enEuDR55oSNi /a0Hh3LfdfOGzpkLtEzdIOUAqpIxidngDJqfnQIc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Colin Ian King , Greg Kroah-Hartman , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 078/237] usbip: tools: fix atoi() on non-null terminated string Date: Sat, 16 Nov 2019 10:38:33 -0500 Message-Id: <20191116154113.7417-78-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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