From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by sourceware.org (Postfix) with ESMTPS id A7E32385783F for ; Tue, 16 May 2023 12:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7E32385783F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=owlfolio.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=owlfolio.org Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 38C9132005B5 for ; Tue, 16 May 2023 08:56:12 -0400 (EDT) Received: from imap45 ([10.202.2.95]) by compute1.internal (MEProxy); Tue, 16 May 2023 08:56:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=owlfolio.org; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1684241771; x=1684328171; bh=Vp ypbtyVS9zW+Cbr4vFczLc9/IuvI0HuGAS8yRsx5tg=; b=VHghEsQ/pqV/hbG61i ZhxYj93Hw7TS4F5+m9hCfuV1zaqUNIGRmW9JieSuF4oOQpkjp9cKMSeyKxPTrUL2 wa8ljMQAupbvNwoYeHbObhHNr3vnII2SBM//a8mCjZk4BhGYiJZmVnIX6O36uQGQ 7NGYZF+8bvgeVCX90F6ZEicuPF9CH8zMjmDY/l5gCpPD5ue/PkQCwD0aDaPy1UYs vU6vZlffghn/wakQFGOA2bbpT5BGTJ8WyrNMGOV1ZRPgG5/vGUZuOLKpsRpKEcL8 kkR3q0cUkRhMpU1UDmJopEPqjyOc/ND/89mgShmnecHziCoSEVAlQsIZmG/BPnEX lWRg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1684241771; x=1684328171; bh=VpypbtyVS9zW+ Cbr4vFczLc9/IuvI0HuGAS8yRsx5tg=; b=a4hf0EZL83aszL9As01Hj9R8dNJgd CTJMAajgf+oVyMchnFw82M2MrLbBNclkyhgLpa/JXQCJJ+oSnmNp/dccYVfOYS1V dh7bQD2t6CsSYpX5oPKiAYHSW9AJ4VI+FySpfySkNev7xfyOoAPcv7v69Cb+IrZ1 hyshKpd/YaYEnQAZ1vf63cpTaBZnQUV/+l1IWmRwRq0mqCkvBFjnSSApfss2h1uB e+bEKllVZ+qKnGsMTx09s9Y/iO/Vg0cRq1w17iEDDczPFq48NQxA1uPf0iYj7pCd TCrIoYalD4FQ58QPF8h9MauCMf7qoI+dfo43e4aDoKYgjREwlDQOXvC+w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehledgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdgkrggt khcuhggvihhnsggvrhhgfdcuoeiirggtkhesohiflhhfohhlihhordhorhhgqeenucggtf frrghtthgvrhhnpefhuefhveeuffetfffgjeetgfekkeehfedtfeelgfehffffveehkeel fefgheffudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpeiirggtkhesohiflhhfohhlihhordhorhhg X-ME-Proxy: Feedback-ID: i876146a2:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7A12D272007A; Tue, 16 May 2023 08:56:11 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-415-gf2b17fe6c3-fm-20230503.001-gf2b17fe6 Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20230516114612.159103-1-adhemerval.zanella@linaro.org> <20230516114612.159103-4-adhemerval.zanella@linaro.org> Date: Tue, 16 May 2023 08:55:51 -0400 From: "Zack Weinberg" To: "GNU libc development" Subject: Re: [PATCH v3 3/3] linux: Add pidfd_getpid Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, May 16, 2023, at 8:38 AM, Luca Boccassi via Libc-alpha wrote: > On Tue, 16 May 2023 at 13:26, Adhemerval Zanella Netto > wrote: >> >> + unsigned long n = strtoul (l, &endp, 10); >> >> + if (l == endp || (n > INT_MAX && n != ULONG_MAX)) >> >> + return 0; >> > >> > How can this tell the difference between '-1' and garbage input? It >> > seems to me this will confuse mangled input here with ESRCH, given the >> > pid in fdinfo is initialized to -1, no? >> >> Because -1 will be parsed as ULONG_MAX. For instance, with the inputs: >> >> Input: | Function result | parse_fdinfo_t >> -------------------|-----------------|----------------------- >> "Pid: 0" | 1 | {1, 0} >> "Pid: 1" | 1 | {1, 1} >> "Pid: 2147483647" | 1 | {1, 2147483647} >> "Pid: 2147483648" | 0 | {0, -1} >> "Pid: -1" | 1 | {1, -1} >> "Pid: -3" | 0 | {0, -1} >> "Pid: -24x" | 0 | {0, -1} >> >> So only if the PID if positive less than INT_MAX or -1 the function >> will set that the PID as found. > > This seems excessively convoluted and fragile to me, relying on > overflows and so on. I cannot stress this enough, in order to use this > from systemd et al I need to be absolutely certain that garbage input > is not treated the same as ESCHR. Why not just use strtoll or so, to > get an exact result out of it? Also, all of the strto* functions are sensitive to the locale. It shouldn't be too hard to make this function async-signal-safe and I think we really ought to. (Actually, why isn't this operation exposed as an ioctl on the pidfd? I thought the kernel people had come around to accepting that parsing text files in /proc is fragile, inconvenient, and slow.) zw