Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bX8aT-0006mM-RX for pgsql-committers@arkaria.postgresql.org; Tue, 09 Aug 2016 15:05:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bX8aT-0000Tj-9u for pgsql-committers@arkaria.postgresql.org; Tue, 09 Aug 2016 15:05:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bX8aF-0000Fe-Io for pgsql-committers@postgresql.org; Tue, 09 Aug 2016 15:04:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bX8aB-0007Gi-M1 for pgsql-committers@postgresql.org; Tue, 09 Aug 2016 15:04:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u79F4YpE023900; Tue, 9 Aug 2016 11:04:34 -0400 From: Tom Lane To: Piotr Stefaniak cc: Peter Eisentraut , "pgsql-committers@postgresql.org" Subject: Re: pgsql: Fix several one-byte buffer over-reads in to_number In-reply-to: References: Comments: In-reply-to Piotr Stefaniak message dated "Mon, 08 Aug 2016 20:16:15 -0000" Date: Tue, 09 Aug 2016 11:04:34 -0400 Message-ID: <23899.1470755074@sss.pgh.pa.us> X-Pg-Spam-Score: -2.3 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-committers Precedence: bulk Sender: pgsql-committers-owner@postgresql.org Piotr Stefaniak writes: > I've been meaning to update my patch like this, but didn't want to > bother you before trying to find more issues with formatting.c (still > haven't found the time for that, sadly): > - if (*Np->inout_p == ' ') > + while (!OVERLOAD_TEST && isspace((unsigned char) *Np->inout_p)) > Np->inout_p++; Meh. I agree that replacing the "== ' '" test with isspace() would be an improvement, since that seems to be the way it's done elsewhere in formatting.c. But changing this into a loop, so that it's willing to consume any amount of whitespace, is a nontrivial change in the specification of to_number(). I'm not at all sure it's a good idea; IMO the point of to_number() is to parse numbers according to a fairly tightly controlled format. I'd even argue that unconditionally consuming a single space is the wrong thing here. Rather, I think what this is meant to be doing is treating a space as one of the possible alternatives for a sign character, and so instead of this what the code ought to be is an alternative on the same footing as '+' or '-', a few lines down: else if (*Np->inout_p == '+') { *Np->number = '+'; /* set + */ Np->inout_p++; } + else if (isspace((unsigned char) *Np->inout_p)) + { + *Np->number = '+'; /* set + */ + Np->inout_p++; + } } } regards, tom lane -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers