Extend the private key stat checking error handling
authorDaniel Gustafsson <[email protected]>
Tue, 30 Nov 2021 22:23:57 +0000 (23:23 +0100)
committerDaniel Gustafsson <[email protected]>
Tue, 30 Nov 2021 22:23:57 +0000 (23:23 +0100)
If the stat operation on the private key failed, the code assumed it
was due to an ENOENT, which may or may not be true. Extend the check
by printing a different error message on non-ENOENT errors for easier
debugging.

Per suggestion by Tom Lane due to an issue with the fairywren animal
in the buildfarm.

Discussion: https://postgr.es/m/1632478.1638305700@sss.pgh.pa.us

src/interfaces/libpq/fe-secure-openssl.c

index a90d891c6ccf9f7a89b4fd4b08a057f6b29d299e..33f095c12ec93799f9f96a500f13feba6cff07c8 100644 (file)
@@ -1235,9 +1235,14 @@ initialize_SSL(PGconn *conn)
 
                if (stat(fnbuf, &buf) != 0)
                {
-                       appendPQExpBuffer(&conn->errorMessage,
-                                                         libpq_gettext("certificate present, but not private key file \"%s\"\n"),
-                                                         fnbuf);
+                       if (errno == ENOENT)
+                               appendPQExpBuffer(&conn->errorMessage,
+                                                                 libpq_gettext("certificate present, but not private key file \"%s\"\n"),
+                                                                 fnbuf);
+                       else
+                               appendPQExpBuffer(&conn->errorMessage,
+                                                                 libpq_gettext("could not stat private key file \"%s\": %m\n"),
+                                                                 fnbuf);
                        return -1;
                }
 #ifndef WIN32