Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMC1G-0006zr-MQ for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Oct 2019 14:17:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMC1E-0007fw-I9 for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Oct 2019 14:17:16 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMC1E-0007fp-AR for pgsql-bugs@lists.postgresql.org; Sun, 20 Oct 2019 14:17:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMC1C-0001Ex-MF for pgsql-bugs@lists.postgresql.org; Sun, 20 Oct 2019 14:17:15 +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 x9KEHBvP013214; Sun, 20 Oct 2019 10:17:11 -0400 From: Tom Lane To: wurongxin@xmu.edu.cn cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16070: A double-free bug in interfaces/libpq/fe-secure-openssl.c In-reply-to: <16070-ffac944519a43c3f@postgresql.org> References: <16070-ffac944519a43c3f@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 20 Oct 2019 08:58:17 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13212.1571581031.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 20 Oct 2019 10:17:11 -0400 Message-ID: <13213.1571581031@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > In > https://github.com/postgres/postgres/blob/REL_10_STABLE/src/interfaces/l= ibpq/fe-secure-openssl.c, > at Line 1206, it would call the function "ENGINE_finish" and free > conn->engine. At Line 1207, it would call the function "ENGINE_free" and > free conn->engine again. This would lead to a double free bug. I don't really believe this; if there were a double-free problem here, we'd surely have noticed it long since. Taking a look at the OpenSSL source code, it looks like engine_free_util decrements a reference count and doesn't actually delete anything until that's gone to zero. So maybe the refcount is 2 at the beginning of this sequence? regards, tom lane