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 1m5DM5-0000Wk-F6 for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Jul 2021 20:25: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 1m5DM3-0007un-17 for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Jul 2021 20:25:39 +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 1m5DM2-0007uf-K8 for pgsql-hackers@lists.postgresql.org; Sun, 18 Jul 2021 20:25:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5DLu-0002Yk-Nv for pgsql-hackers@postgresql.org; Sun, 18 Jul 2021 20:25:36 +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 16IKPN5I161030; Sun, 18 Jul 2021 16:25:23 -0400 From: Tom Lane To: Amit Kapila cc: Peter Smith , vignesh C , "tanghy.fnst@fujitsu.com" , Ajin Cherian , Greg Nancarrow , PostgreSQL Hackers Subject: Re: [HACKERS] logical decoding of two-phase transactions In-reply-to: References: message dated "Wed, 14 Jul 2021 11:52:58 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <161028.1626639923.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 18 Jul 2021 16:25:23 -0400 Message-ID: <161029.1626639923@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Amit Kapila writes: > Pushed. Coverity thinks this has security issues, and I agree. /srv/coverity/git/pgsql-git/postgresql/src/backend/replication/logical/pro= to.c: 144 in logicalrep_read_begin_prepare() 143 /* read gid (copy it into a pre-allocated buffer) */ >>> CID 1487517: Security best practices violations (STRING_OVERFLOW= ) >>> You might overrun the 200-character fixed-size string "begin_data-= >gid" by copying the return value of "pq_getmsgstring" without checking th= e length. 144 strcpy(begin_data->gid, pq_getmsgstring(in)); 200 /* read gid (copy it into a pre-allocated buffer) */ >>> CID 1487515: Security best practices violations (STRING_OVERFLOW= ) >>> You might overrun the 200-character fixed-size string "prepare_dat= a->gid" by copying the return value of "pq_getmsgstring" without checking = the length. 201 strcpy(prepare_data->gid, pq_getmsgstring(in)); 256 /* read gid (copy it into a pre-allocated buffer) */ >>> CID 1487516: Security best practices violations (STRING_OVERFLOW= ) >>> You might overrun the 200-character fixed-size string "prepare_dat= a->gid" by copying the return value of "pq_getmsgstring" without checking = the length. 257 strcpy(prepare_data->gid, pq_getmsgstring(in)); 316 /* read gid (copy it into a pre-allocated buffer) */ >>> CID 1487519: Security best practices violations (STRING_OVERFLOW= ) >>> You might overrun the 200-character fixed-size string "rollback_da= ta->gid" by copying the return value of "pq_getmsgstring" without checking= the length. 317 strcpy(rollback_data->gid, pq_getmsgstring(in)); I think you'd be way better off making the gid fields be "char *" and pstrdup'ing the result of pq_getmsgstring. Another possibility perhaps is to use strlcpy, but I'd only go that way if it's important to constrain the received strings to 200 bytes. regards, tom lane