]> granicus.if.org Git - postgresql/commitdiff
Fix some more problems with testing error returns from SSL.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Aug 2003 17:25:29 +0000 (17:25 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Aug 2003 17:25:29 +0000 (17:25 +0000)
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-secure.c

index f94f46dd59bc21aef8b0152a55d56339d67cf5c4..5008d5bf6325cc0b852e1e2362f02105ad070ae0 100644 (file)
@@ -25,7 +25,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.85 2002/10/24 23:35:55 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.85.2.1 2003/08/04 17:25:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -553,7 +553,18 @@ retry3:
         * file is ready. Grumble.      Fortunately, we don't expect this path to
         * be taken much, since in normal practice we should not be trying to
         * read data unless the file selected for reading already.
+        *
+        * In SSL mode it's even worse: SSL_read() could say WANT_READ and then
+        * data could arrive before we make the pqReadReady() test.  So we must
+        * play dumb and assume there is more data, relying on the SSL layer to
+        * detect true EOF.
         */
+
+#ifdef USE_SSL
+       if (conn->ssl)
+               return 0;
+#endif
+
        switch (pqReadReady(conn))
        {
                case 0:
index 2a4d394187d720f95d7af4bf1e4292c983a1002b..4d3ffcc5b8e090a4e375db3e8865c31547d54d11 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.15.2.5 2003/04/10 23:03:13 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.15.2.6 2003/08/04 17:25:29 tgl Exp $
  *
  * NOTES
  *       The client *requires* a valid server certificate.  Since
@@ -278,21 +278,25 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
                                                                          libpq_gettext("SSL SYSCALL error: %s\n"),
                                                                          SOCK_STRERROR(SOCK_ERRNO));
                                else
+                               {
                                        printfPQExpBuffer(&conn->errorMessage,
                                                                          libpq_gettext("SSL SYSCALL error: EOF detected\n"));
+                                       SOCK_ERRNO = ECONNRESET;
+                                       n = -1;
+                               }
                                break;
                        case SSL_ERROR_SSL:
                                printfPQExpBuffer(&conn->errorMessage,
                                          libpq_gettext("SSL error: %s\n"), SSLerrmessage());
                                /* fall through */
                        case SSL_ERROR_ZERO_RETURN:
-                               pqsecure_close(conn);
                                SOCK_ERRNO = ECONNRESET;
                                n = -1;
                                break;
                        default:
                                printfPQExpBuffer(&conn->errorMessage,
                                                                  libpq_gettext("Unknown SSL error code\n"));
+                               n = -1;
                                break;
                }
        }
@@ -334,21 +338,25 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
                                                                          libpq_gettext("SSL SYSCALL error: %s\n"),
                                                                          SOCK_STRERROR(SOCK_ERRNO));
                                else
+                               {
                                        printfPQExpBuffer(&conn->errorMessage,
                                                                          libpq_gettext("SSL SYSCALL error: EOF detected\n"));
+                                       SOCK_ERRNO = ECONNRESET;
+                                       n = -1;
+                               }
                                break;
                        case SSL_ERROR_SSL:
                                printfPQExpBuffer(&conn->errorMessage,
                                          libpq_gettext("SSL error: %s\n"), SSLerrmessage());
                                /* fall through */
                        case SSL_ERROR_ZERO_RETURN:
-                               pqsecure_close(conn);
                                SOCK_ERRNO = ECONNRESET;
                                n = -1;
                                break;
                        default:
                                printfPQExpBuffer(&conn->errorMessage,
                                                                  libpq_gettext("Unknown SSL error code\n"));
+                               n = -1;
                                break;
                }
        }