Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fq0Ax-0003uF-RQ for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Aug 2018 18:05:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fq0Aw-0001Nr-6t for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Aug 2018 18:05:42 +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.89) (envelope-from ) id 1fq0Aw-0001Nj-02 for pgsql-hackers@lists.postgresql.org; Wed, 15 Aug 2018 18:05:42 +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.89) (envelope-from ) id 1fq0Ao-0003v2-Go for pgsql-hackers@lists.postgresql.org; Wed, 15 Aug 2018 18:05:41 +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 w7FI5THK017491; Wed, 15 Aug 2018 14:05:29 -0400 From: Tom Lane To: Alvaro Herrera cc: Robert Haas , PostgreSQL Hackers Subject: Re: C99 compliance for src/port/snprintf.c In-reply-to: <13169.1534352739@sss.pgh.pa.us> References: <20180815155643.zx4qpcmpvhemefyg@alvherre.pgsql> <13169.1534352739@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 15 Aug 2018 13:05:39 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17489.1534356329.1@sss.pgh.pa.us> Date: Wed, 15 Aug 2018 14:05:29 -0400 Message-ID: <17490.1534356329@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Meh --- the hazards of back-patching seem to me to be more hypothetical > than the benefits. Still, I seem to be in the minority, so I withdraw > the proposal to back-patch. Actually, after digging around a bit, I'm excited about this again. There are only a couple dozen places in our tree that pay any attention to the result of (v)snprintf, but with the exception of psnprintf, appendPQExpBufferVA, and one or two other places, *they're all assuming C99 semantics*, and will fail to detect buffer overflow with the pre-C99 behavior. Probably a lot of these are not live bugs because buffer overrun is not ever going to occur in practice. But at least pg_upgrade and pg_regress are constructing command strings including externally supplied paths, so overrun doesn't seem impossible. If it happened, they'd merrily proceed to execute a truncated command. If we don't backpatch the snprintf change, we're morally obliged to back-patch some other fix for these places. At least one of them, in plperl's pport.h, is not our code and so changing it seems like a bad idea. Still want to argue for no backpatch? regards, tom lane PS: I also found a couple of places that are just wrong regardless of semantics: they're checking overflow by "result > bufsize", not "result >= bufsize". Will fix those in any case.