diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2019-09-05 08:15:58 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2019-09-05 08:30:42 +0200 |
commit | 74a308cf5221f491776fcdb4dc36eb61678dbc6f (patch) | |
tree | c2e9a146616d9b40dcd606db4030abcd1b1fe25b /src/interfaces/libpq/fe-connect.c | |
parent | ae060a52b2881ea842f596fa78b8d09f9a91b149 (diff) |
Use explicit_bzero
Use the explicit_bzero() function in places where it is important that
security information such as passwords is cleared from memory. There
might be other places where it could be useful; this is just an
initial collection.
For platforms that don't have explicit_bzero(), provide various
fallback implementations. (explicit_bzero() itself isn't standard,
but as Linux/glibc, FreeBSD, and OpenBSD have it, it's the most common
spelling, so it makes sense to make that the invocation point.)
Discussion: https://www.postgresql.org/message-id/flat/42d26bde-5d5b-c90d-87ae-6cab875f73be%402ndquadrant.com
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 7f1fd2f45eb..9a5aa1a3c5f 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -3885,7 +3885,10 @@ freePGconn(PGconn *conn) if (conn->connhost[i].port != NULL) free(conn->connhost[i].port); if (conn->connhost[i].password != NULL) + { + explicit_bzero(conn->connhost[i].password, strlen(conn->connhost[i].password)); free(conn->connhost[i].password); + } } free(conn->connhost); } @@ -3919,7 +3922,10 @@ freePGconn(PGconn *conn) if (conn->pguser) free(conn->pguser); if (conn->pgpass) + { + explicit_bzero(conn->pgpass, strlen(conn->pgpass)); free(conn->pgpass); + } if (conn->pgpassfile) free(conn->pgpassfile); if (conn->keepalives) @@ -6931,6 +6937,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname, if (!ret) { /* Out of memory. XXX: an error message would be nice. */ + explicit_bzero(buf, sizeof(buf)); return NULL; } @@ -6947,6 +6954,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname, } fclose(fp); + explicit_bzero(buf, sizeof(buf)); return NULL; #undef LINELEN |