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 1nb37g-00033P-7c for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Apr 2022 16:30:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nb37f-0007LH-3V for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Apr 2022 16:30:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nb37e-0007L8-Ql for pgsql-hackers@lists.postgresql.org; Sun, 03 Apr 2022 16:30:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nb37c-0003dh-T8 for pgsql-hackers@lists.postgresql.org; Sun, 03 Apr 2022 16:30:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 233GUWo31645294; Sun, 3 Apr 2022 12:30:32 -0400 From: Tom Lane To: Joseph Koshakow cc: Andres Freund , PostgreSQL Hackers Subject: Re: Fix overflow in DecodeInterval In-reply-to: References: <2176379.1644612942@sss.pgh.pa.us> <20220213035150.wusl6mmbeb3m3jpy@alap3.anarazel.de> <20220213203037.ie7bgjrodupzxhda@alap3.anarazel.de> <2726280.1644784719@sss.pgh.pa.us> <20220215162809.yryv7bj24lxfoo37@alap3.anarazel.de> <410974.1645400227@sss.pgh.pa.us> <1523458.1648926618@sss.pgh.pa.us> <1531188.1648930455@sss.pgh.pa.us> <1592893.1648969747@sss.pgh.pa.us> <1640460.1649000698@sss.pgh.pa.us> <1642579.1649001803@sss.pgh.pa.us> Comments: In-reply-to Joseph Koshakow message dated "Sun, 03 Apr 2022 12:22:12 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1645292.1649003432.1@sss.pgh.pa.us> Date: Sun, 03 Apr 2022 12:30:32 -0400 Message-ID: <1645293.1649003432@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Joseph Koshakow writes: > On Sun, Apr 3, 2022 at 12:03 PM Tom Lane wrote: >> Oh ... a bit of testing says that strtod() on an empty string >> succeeds (returning zero) on Linux, but fails with EINVAL on >> AIX. The latter is a lot less surprising than the former, >> so we'd better cope. > I'm not sure I follow exactly. Where would we pass an empty > string to strtod()? Wouldn't we be passing a string with a > single character of '.'? Oh, I was thinking that we passed "cp + 1" to strtod, but that was just caffeine deprivation. You're right, what we are asking it to parse is "." not "". The result is the same though: per testing, AIX sets EINVAL and Linux doesn't. > So I think we need to check that endptr has moved both after > the call to strtoi64() and strtod(). I'm not sure we need to do that explicitly, given that there's a check later as to whether endptr is pointing at \0; that will fail if endptr wasn't advanced. The fix I was loosely envisioning was to check for cp[1] == '\0' and not bother calling strtod() in that case. regards, tom lane