From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 995C8342CBA for ; Wed, 20 May 2026 16:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779295212; cv=none; b=A33t3PYVRj8Qzcs4CgYO407fwPEu8UfeToUvMazaWCTK421nAnmaqbvwritBMwsH7+Han8rZnlZZpi9KNo/rgTVCqaGwXCCOgTbfCNNVVZn8xvHOaE68jn33GKeYIo9168rS0TTajNubie13NXD1kQBNwbbh/cZA1KhCr9KZqvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779295212; c=relaxed/simple; bh=ednwvukeYD77oPVmuiYtjLnecuATNoiXfVHZ95S5PPg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CBBMIzU8Bzjl8RPzXmMmRW6GV5iHLzIDzP+yibdjMZnFUz9Tr+ggDGRxJNfo57Ms97BnfzOVa5GwWtCJF9HL07yHt2OzWENKmXxuMEhcPrVz+rFe78rZeBafmTI0dpCBtXgUZ7x5lDNl4yxbjes5KCEmGPQ607rAz1LGk7WJ+8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=XR+52Hqf; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="XR+52Hqf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1779295208; bh=ednwvukeYD77oPVmuiYtjLnecuATNoiXfVHZ95S5PPg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XR+52Hqfej7BXNHoofjpGvBpIXDHlvXkjbSFAAcsbhVjPTV+8cKXp1glAb93T4gLj Au2C9h2U2zB8ZsQIfKnWSw43w4SwCjsKjWxaX102rKrqD12nF/Zzahr48gsQ/eBaa/ 14YExs2PRh5nt9ImSECPlggEEMrJN9Xbcvb9ur+Y= Date: Wed, 20 May 2026 18:40:07 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Daniel Palmer Cc: w@1wt.eu, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/nolibc: getopt: Fix potential out of bounds access Message-ID: <533720f8-b13b-4942-bfeb-92a7a6ef9fd7@t-8ch.de> References: <20260520111931.1027758-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260520111931.1027758-1-daniel@thingy.jp> Hi Daniel, On 2026-05-20 20:19:31+0900, Daniel Palmer wrote: > Running clang-tidy on a program that uses getopt() from nolibc > this warning appears: > > getopt.h:80:6: warning: Out of bound access to memory after the end of the string literal [clang-analyzer-security.ArrayBound] > 80 | if (optstring[i] == ':') { > > Claude was asked for a reproducer and the human fixed up version > looks like this: Thanks for the report and patch! (...) > Claude suggests using `-fsanitize=address` to detect the issue > but that doesn't work for nolibc so lets do it manually with > gdb: It works fine to copy the nolibc getopt() implementation into a new normal source file and compile it with asan there. That reproduces the issue and confirms the fix. I'll apply your fix with a trimmed commit message. (...) Thomas