From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F7D2301002 for ; Mon, 22 Dec 2025 09:48:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.68 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766396917; cv=none; b=IqdUEth9hN8/5ZJ4l992IMnspy3miya3VDyxOl6FyHpVp4+O2RcsvaVypHmX2+MuFd7PhjViS3ddXOmd5pgJ8JrH4IzrutYzzUNs32aKUTNEPaCG7Ma3iVHyx49d7jRb4Egq7/hwchXBq3gpCC64asWZ0eYtk3jCKG2r7QgxDLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766396917; c=relaxed/simple; bh=BFWeRYpk582Dj1H10KmnL6ohapHXluTPgBRd3PojY9k=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WjAI/K5iFYqPczcFdU1Iw+Xi5uxD11B9U7uMPFx9wont3uuwBvqxovKnrcQ89F7l0B5yVo/8owSeGQKVlv5tNIU8doU3qrYf3GK4vSNOeFETaSxULiNtulZB1/T0bhrqUTlZgXcAn9sK9loicpkbyXvTmfENNGvyFkqp9dni8qQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F/CE8az6; arc=none smtp.client-ip=209.85.128.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F/CE8az6" Received: by mail-wm1-f68.google.com with SMTP id 5b1f17b1804b1-4775e891b5eso14971035e9.2 for ; Mon, 22 Dec 2025 01:48:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766396914; x=1767001714; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Cpp2j64eyQIDdIrB75XVaxQv4OqlhELwCC5ZDUyvq6Q=; b=F/CE8az61xc32bEpCmnEN1yiWwVC/pxbbuDzDyELf8esdG/d8JCdmeZP1mR1np4DxX Rct6ktFeFKBF6ePvxoLfGTaJgv1YbMWqDTjRuFRGUGXwfLRFFDuB91HfujfLRvUm/aKm R8q2zVdAwA/nJ+4l5EBt2hCP2TA1sV4c8vjEZs7l6yKb970ZAiM6P+cr5M9sJm9Cghmw FXQXJ9d4P0BWk+LF/uAlHLdZsV0uMMDhxrpjoV0yQSo41y6mdzHbzXXCBSRRB705s3mv OBIkXCkatYnxsNcbI+kbkFrGWppk6Ei5BC3K0BOhymxg2Nwbi6oIB0JmDatAEm175f9D WpeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766396914; x=1767001714; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Cpp2j64eyQIDdIrB75XVaxQv4OqlhELwCC5ZDUyvq6Q=; b=HL+mF7iJg/ULffnxMqFpdYXMje8csD07DuU0Jm6w/A8qQckgby2tvTY9Ei2GFmEscL AWId0uxTiqjgWkyGeA4nngRT46MwAHOxgLHFEgpwikqw6/rqD4LL9KxZcWyY5TBKg/S+ vbCjrA+nlKvs0/teh9DJuxl1TdSci0tMciuJp34zbrQmRz0wa+WRnFgP/uC3K5QYpUuC F6DHFabrv2S17LjU+AecD0pC0Oh+bRVZq/DUSO6I48KZ1DoZ/SppGtUi5lYjW8diYpKx Q72r+rmJTBbXTQhBLQWmPgp6FyBBbTW1mF57sCToOJ5aSXFquZ94OVJUnJVHuaSBMQ3E AMRQ== X-Forwarded-Encrypted: i=1; AJvYcCXyzLbQN1Mp6+ZxSaGKxag4mQpo4NYT8SLRFwnY0shVsATX0or5bUwcE/p7zggINa3nHPdLo+rCZZ2x000=@vger.kernel.org X-Gm-Message-State: AOJu0YwI1qLgfi6TVlcr6rYbnTjDJQQUFO1P2XDZ5j+kwAOEZxB3fM5b 7BAlMytl7SJsUj9a5wDFR5pjuwkaMgtH1Kbs+QvkJvPmtX93BuEwg9GOxyKaf/WB X-Gm-Gg: AY/fxX4kvaB8EtcQrhHRffn0m/H6XP0hjCdoMOPacvL1Bdwvclgeg7lLib5FNjWqWyh LrAATa25PPb6uyJ7+o0d7NlpIRJNkazDGRXyrQihrexHl+Al1qb1ZLmDw4VnA0BkGr1C9F4Bu/k Hrm90yq02omb0K7RPAX5HkOvs8f/BUAHtJJhJoRN9E3USr2nSD9SS+ZQr1VslDzKfUHrrbD+ogf vUIBjnda0BuSG0/qi6CtYb+HP8Ymi+9UbjkxcV8/xQCzyOVHV/J4S/D7jKywz4BBksmpcYWWHYW Zz+feAkcJptJXw+b6rkLeTRQoZxo7EMa7ukkSpbw9rM9umrL1uoboonM+2AqU4auJyjUo3Z6Tya CIj0jZ7Mkk3wJjLWi1L33JWfIZps5ve0qana5+6pw3x9DZmSaonj2+Z9Ams6NnqOHRENXcn+MFQ Mt3zzSve8fqzXzqJkpZMyI/3pPpW5DL3SPxAUM4zC+OfxVqjiFEDU= X-Google-Smtp-Source: AGHT+IF6jYkceDSxr0q7W5Uf/me1u68y0/0ia7Af2JYTdBnbk2BDeEsYBndbKG1YGF/M4co0yuY0Mg== X-Received: by 2002:a05:600c:4506:b0:477:9392:8557 with SMTP id 5b1f17b1804b1-47d1957711fmr98592555e9.18.1766396913629; Mon, 22 Dec 2025 01:48:33 -0800 (PST) Received: from pumpkin (host-2-103-239-165.as13285.net. [2.103.239.165]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47be272e46fsm231821355e9.4.2025.12.22.01.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Dec 2025 01:48:33 -0800 (PST) Date: Mon, 22 Dec 2025 09:48:28 +0000 From: David Laight To: Li Wang Cc: akpm@linux-foundation.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, David Hildenbrand , Mark Brown , Shuah Khan , Waiman Long Subject: Re: [PATCH v3 1/3] selftests/mm/write_to_hugetlbfs: parse -s as size_t Message-ID: <20251222094828.2783d9e5@pumpkin> In-Reply-To: References: <20251221122639.3168038-1-liwang@redhat.com> <20251221122639.3168038-2-liwang@redhat.com> <20251221221052.3b769fc2@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 22 Dec 2025 09:45:41 +0800 Li Wang wrote: > On Mon, Dec 22, 2025 at 6:11=E2=80=AFAM David Laight > wrote: >=20 > > On Sun, 21 Dec 2025 20:26:37 +0800 > > Li Wang wrote: > > =20 > > > write_to_hugetlbfs currently parses the -s size argument with atoi() > > > into an int. This silently accepts malformed input, cannot report =20 > > overflow, =20 > > > and can truncate large sizes. =20 > > > > And sscanf() will just ignore invalid trailing characters. > > Probably much the same as atoi() apart from a leading '-'. > > > > Maybe you could use "%zu%c" and check the count is 1 - but I bet > > some static checker won't like that. > > =20 >=20 > Yes, that would be stronger, since it would reject trailing garbage. > But for a selftest this is probably sufficient: switching to size_t and > parsing with "%zu" already avoids the int truncation issue. Have you checked at what does sscanf() does with an overlong digit string? I'd guess that it just processes all the digits and then masks the result to fix (like the kernel one does). It reality scanf() is 'not the function you are lookign for'. IIRC the 'SUS' (used to) say that this was absolutely fine for command line parsing for 'standard utilities'. It is best to use strtoul() and check the 'end' character is '\0'. David >=20 > @Andrew Morton , >=20 > Hi Andrew, I noticed you have addedthe patches to your mm-new branch, > Let me know if you prefer the "%zu%c" enhancement in a new version. >=20 >=20