Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YRAEL-0003b3-K1 for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Feb 2015 02:00:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YRAEL-0006sR-2s for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Feb 2015 02:00:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YRAEK-0006sH-0O for pgsql-bugs@postgresql.org; Fri, 27 Feb 2015 02:00:40 +0000 Received: from zcs.4linux.com.br ([107.23.21.113]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YRAEE-0000Ec-WB for pgsql-bugs@postgresql.org; Fri, 27 Feb 2015 02:00:38 +0000 Received: from localhost (localhost.4linux.com.br [127.0.0.1]) by zcs.4linux.com.br (Postfix) with ESMTP id 7EFD2640463; Fri, 27 Feb 2015 02:00:31 +0000 (UTC) Received: from zcs.4linux.com.br ([127.0.0.1]) by localhost (zcs.4linux.com.br [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hDdiar8fNwHy; Fri, 27 Feb 2015 02:00:31 +0000 (UTC) Received: from localhost (localhost.4linux.com.br [127.0.0.1]) by zcs.4linux.com.br (Postfix) with ESMTP id 4432264047D; Fri, 27 Feb 2015 02:00:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.9.2 zcs.4linux.com.br 4432264047D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=4linux.com.br; s=1B7D2840-3782-11E4-AF92-188349474E95; t=1425002431; bh=BvUVAljhHB7g5yaIoXjBZj0UII2QF/LEDKrvbYc68eU=; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding; b=U593I6ANvWV8zY2PkzO5vywGgxqsb6ay9uorsKiaGZsJpKoXQdLTrvibyHeChKX+p 0+t8nDPseNhTaIDXY5BBS2lcpeEusqdkWuHdWvxRniOaDtpv4XNLTGMSQU1/Z6n1+z yG5SznV6AVuhGp179csIM7fEgfDJZwSCFXmFKokM= X-Virus-Scanned: amavisd-new at 4linux.com.br Received: from zcs.4linux.com.br ([127.0.0.1]) by localhost (zcs.4linux.com.br [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id rWZKLby0Y_Cr; Fri, 27 Feb 2015 02:00:31 +0000 (UTC) Received: from zcs.4linux.com.br (zcs.4linux.com.br [192.168.11.10]) by zcs.4linux.com.br (Postfix) with ESMTP id 1C7A0640463; Fri, 27 Feb 2015 02:00:31 +0000 (UTC) Date: Thu, 26 Feb 2015 23:00:29 -0300 (BRT) From: william.welter@4linux.com.br To: Heikki Linnakangas Cc: pgsql-bugs@postgresql.org Message-ID: <319431910.43023.1425002429817.JavaMail.zimbra@4linux.com.br> In-Reply-To: <54EDD30D.5050107@vmware.com> References: <20150224030956.2529.83279@wrigleys.postgresql.org> <54EDD30D.5050107@vmware.com> Subject: Re: BUG #12799: libpq - SSL pqsecure_read() doesn't clean openssl error queue before reading MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [177.33.9.191] X-Mailer: Zimbra 8.0.8_GA_6184 (ZimbraWebClient - FF19 (Linux)/8.0.8_GA_6184) Thread-Topic: BUG #12799: libpq - SSL pqsecure_read() doesn't clean openssl error queue before reading Thread-Index: 3AFmtU5ijVTlMBop3NznZnQgfJjGvQ== X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org > > The OpenSSL manual doesn't directly require you to call > ERR_clear_error() before every SSL_* call. It just requires that you > ensure that the error queue is empty. Libpq ensures that by always > clearing the queue *after* an error happens, in SSLerrmessage(). > > Ok, i understand. > I'm actually not 100% sure we clear the error queue after every error. > Looking at the OpenSSL sources on SSL_get_error(), it seems possible > that it returns SSL_ERROR_SYSCALL, with an error in the error queue. The > libpq code does not call SSLerrmessag() when SSL_get_error() returns > SSL_ERROR_SYSCALL, so that would leave the error dangling in the queue. > Also, if there are multiple errors in the queue, we only return and > remove from the queue the first one. > > So should we clear the error queue before each call, just to be sure? > The risk is that the application has performed some other OpenSSL > operations, outside libpq, but not checked the error queue yet, and when > we clear the queue, the original error is gone and isn't reported. An > application probably shouldn't do that, you should check the error after > each SSL call, and not leave the error dangling in the error queue as a > landmine for the next SSL call. OTOH, if the application is built so > that the error queue is cleared before each SSL call, not after, that's > incompatible with the way libpq currently works. And that's certainly a > much more common practice than the hypothetical application that would > miss the error if it's cleared unexpectedly. If i understand correctly: - If libpq clear the error queue before each call this can break current applications that not check error queue immedialty after calls. - But if libpq not clear the queue, application can leave errors on the queue which lead libpq throws unrelated errors. On PHP case, the problem is that the queue is only cleared if the developer explicit call "openssl_error_string()" for each openssl function they called before. I think this behavior can be changed on PHP to prevent this kind of problem with libpq or other libs that use openssl. > > Overall, I agree we should clear the error queue before each SSL call. > It makes the application as whole more robust. > > > The solution is simple, see following patches: > > Yeah. Should also do the same in the backend, and also before > SSL_connect/SSL_accept() calls. I.e. any time SSL_get_error is used. Question: Is possible to fix this to next major release ? (im volunteering) > > - Heikki > > -- > Message protected by MailGuard: e-mail anti-virus, anti-spam and content > filtering.http://www.mailguard.com.au/mg > Click here to report this message as spam: > https://console.mailguard.com.au/ras/1LubMvNYuN/6iGxWUBDMTyqo5LXNO4F30/0 > > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs