Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lm1Bl-0006vT-M4 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 May 2021 21:35:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lm1Bk-0002mb-AW for pgsql-hackers@arkaria.postgresql.org; Wed, 26 May 2021 21:35:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lm1Bk-0002mS-2r for pgsql-hackers@lists.postgresql.org; Wed, 26 May 2021 21:35:40 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lm1Bh-0003GV-5A for pgsql-hackers@lists.postgresql.org; Wed, 26 May 2021 21:35:39 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 11B501466; Wed, 26 May 2021 17:35:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 26 May 2021 17:35:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=tvdJowiYsW9IHuRbtYge61HUqh1wJO0lFDyzyBhUHG8=; b=DV3fwNLj 9XsfNI7nvE3SJQ+Q/cVKRBv5J3skzO8hbuMJZ75XzwzmXryq0REwq5K8LjBOzXce lR8ignEhGSxiTs+RfuQjs2r3sCpxtfAaCzQwozluTGL8vMiun1kq1DKRK9jwvHUx SyWPfMnmgMowPBHu0wvHOOv9yJ7qtsFYH/TLUiynAoz9AoMN/KLvWKuS3frNHSXs p2NvcQm6QlI4+aoLJJUMB7ksaHzdIk+tw4+HBEDPZIHzqtzBWtxwrrg5RyGC2IyA tCxwHYWoNfreTpD3KmNmvbT3BPJgBC15ZM/4vr9n62WrX907EkVEJOs1Cqsepbjo Ai/UE3TrJNp5HQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdekfedgudeigecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjgesthekredttddtudenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepkeekleevgfeiudelffeigeekvdeltdelvdevieetledt tefhfeffleffkeejfeelnecuffhomhgrihhnpehpohhsthhgrhdrvghsnecukfhppedule dtrdelhedrudelrdelheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.19.95]) by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 May 2021 17:35:34 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id E20BA2A0A8B; Wed, 26 May 2021 17:35:30 -0400 (-04) Date: Wed, 26 May 2021 17:35:30 -0400 From: Alvaro Herrera To: Bharath Rupireddy Cc: PostgreSQL Hackers Subject: Re: Incorrect usage of strtol, atoi for non-numeric junk inputs Message-ID: <202105262135.zcl7jtvfz3v7@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-May-19, Bharath Rupireddy wrote: > While working on [1], I found that some parts of the code is using > strtol and atoi without checking for non-numeric junk input strings. I > found this strange. Most of the time users provide proper numeric > strings but there can be some scenarios where these strings are not > user-supplied but generated by some other code which may contain > non-numeric strings. Shouldn't the code use strtol or atoi > appropriately and error out in such cases? One way to fix this once > and for all is to have a common API something like int > pg_strtol/pg_str_convert_to_int(char *opt_name, char *opt_value) which > returns a generic message upon invalid strings ("invalid value \"%s\" > is provided for option \"%s\", opt_name, opt_value) and returns > integers on successful parsing. Hi, how is this related to https://postgr.es/m/20191028012000.GA59064@begriffs.com ? -- Álvaro Herrera Valdivia, Chile