Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suxKo-00BS2v-BX for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Sep 2024 17:03:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1suxKm-006bbx-30 for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Sep 2024 17:03:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suxKl-006bbo-Pe for pgsql-hackers@lists.postgresql.org; Sun, 29 Sep 2024 17:03:47 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suxKd-001i6d-Su for pgsql-hackers@postgresql.org; Sun, 29 Sep 2024 17:03:46 +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 48TH3cEM1240824; Sun, 29 Sep 2024 13:03:39 -0400 From: Tom Lane To: Robert Haas cc: Amul Sul , Sravan Kumar , PostgreSQL-development Subject: Re: pg_verifybackup: TAR format backup verification In-reply-to: <1115881.1727564342@sss.pgh.pa.us> References: <1115881.1727564342@sss.pgh.pa.! us> Comments: In-reply-to Tom Lane message dated "Sat, 28 Sep 2024 18:59:02 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1240822.1727629418.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Sep 2024 13:03:38 -0400 Message-ID: <1240823.1727629418@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Piling on a bit ... Coverity reported the following issues in this new code. I have not analyzed them to see if they're real problems. __________________________________________________________________________= ______________________________ *** CID 1620458: Resource leaks (RESOURCE_LEAK) /srv/coverity/git/pgsql-git/postgresql/src/bin/pg_verifybackup/pg_verifyba= ckup.c: 1025 in verify_tar_file() 1019 relpath); 1020 = 1021 /* Close the file. */ 1022 if (close(fd) !=3D 0) 1023 report_backup_error(context, "could not close file \"%s\": %m", 1024 relpath); >>> CID 1620458: Resource leaks (RESOURCE_LEAK) >>> Variable "buffer" going out of scope leaks the storage it points t= o. 1025 } 1026 = 1027 /* 1028 * Scan the hash table for entries where the 'matched' flag is no= t set; report 1029 * that such files are present in the manifest but not on disk. 1030 */ __________________________________________________________________________= ______________________________ *** CID 1620457: Memory - illegal accesses (OVERRUN) /srv/coverity/git/pgsql-git/postgresql/src/bin/pg_verifybackup/astreamer_v= erify.c: 349 in member_copy_control_data() 343 */ 344 if (mystreamer->control_file_bytes <=3D sizeof(ControlFileData)) 345 { 346 int remaining; 347 = 348 remaining =3D sizeof(ControlFileData) - mystreamer->control_file= _bytes; >>> CID 1620457: Memory - illegal accesses (OVERRUN) >>> Overrunning array of 296 bytes at byte offset 296 by dereferencing= pointer "(char *)&mystreamer->control_file + mystreamer->control_file_byt= es". 349 memcpy(((char *) &mystreamer->control_file) 350 + mystreamer->control_file_bytes, 351 data, Min(len, remaining)); 352 } 353 = 354 /* Remember how many bytes we saw, even if we didn't buffer them.= */ __________________________________________________________________________= ______________________________ *** CID 1620456: Null pointer dereferences (FORWARD_NULL) /srv/coverity/git/pgsql-git/postgresql/src/bin/pg_verifybackup/pg_verifyba= ckup.c: 939 in precheck_tar_backup_file() 933 "file \"%s\" is not expected in a tar format backup", 934 relpath); 935 tblspc_oid =3D (Oid) num; 936 } 937 = 938 /* Now, check the compression type of the tar */ >>> CID 1620456: Null pointer dereferences (FORWARD_NULL) >>> Passing null pointer "suffix" to "strcmp", which dereferences it. 939 if (strcmp(suffix, ".tar") =3D=3D 0) 940 compress_algorithm =3D PG_COMPRESSION_NONE; 941 else if (strcmp(suffix, ".tgz") =3D=3D 0) 942 compress_algorithm =3D PG_COMPRESSION_GZIP; 943 else if (strcmp(suffix, ".tar.gz") =3D=3D 0) 944 compress_algorithm =3D PG_COMPRESSION_GZIP; regards, tom lane