pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: using explicit_bzero
Date: Sun, 23 Jun 2019 21:57:18 +0200
Message-ID: <2b38e01a-0f7c-33f8-d4a9-edfcf85f9e4b@2ndquadrant.com> (raw)
In-Reply-To: <26f25674-9c4d-241f-0e74-3fee9860ca13@2ndquadrant.com>
References: <42d26bde-5d5b-c90d-87ae-6cab875f73be@2ndquadrant.com>
	<27860.1561123531@sss.pgh.pa.us>
	<26f25674-9c4d-241f-0e74-3fee9860ca13@2ndquadrant.com>

On 2019-06-23 21:55, Peter Eisentraut wrote:
> On 2019-06-21 15:25, Tom Lane wrote:
>> Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
>>> +#ifndef HAVE_EXPLICIT_BZERO
>>> +#define explicit_bzero(b, len) bzero(b, len)
>>> +#endif
>>
>> This presumes that every platform has bzero, which is unsafe (POSIX
>> doesn't specify it) and is an assumption we kicked to the curb a dozen
>> years ago (067a5cdb3).  Please use memset() for the substitute instead.
> 
> OK, done.

and with patch attached

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Use-explicit_bzero.patch (text/plain, 4.3K) download From e193fbcf04833de829069b5e737a27b83c667703 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Sun, 23 Jun 2019 21:53:14 +0200 Subject: [PATCH v2] Use explicit_bzero --- configure | 2 +- configure.in | 1 + src/backend/libpq/be-secure-common.c | 1 + src/include/pg_config.h.in | 3 +++ src/include/port.h | 4 ++++ src/interfaces/libpq/fe-connect.c | 8 ++++++++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 8d47071e4a..c88153fff5 100755 --- a/configure +++ b/configure @@ -15176,7 +15176,7 @@ fi LIBS_including_readline="$LIBS" LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'` -for ac_func in cbrt clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink setproctitle setproctitle_fast setsid shm_open strchrnul strsignal symlink sync_file_range uselocale utime utimes wcstombs_l +for ac_func in cbrt clock_gettime copyfile explicit_bzero fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink setproctitle setproctitle_fast setsid shm_open strchrnul strsignal symlink sync_file_range uselocale utime utimes wcstombs_l do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.in b/configure.in index 74938d4190..7e96d1d419 100644 --- a/configure.in +++ b/configure.in @@ -1615,6 +1615,7 @@ AC_CHECK_FUNCS(m4_normalize([ cbrt clock_gettime copyfile + explicit_bzero fdatasync getifaddrs getpeerucred diff --git a/src/backend/libpq/be-secure-common.c b/src/backend/libpq/be-secure-common.c index 877226d377..4c1c6cb3c4 100644 --- a/src/backend/libpq/be-secure-common.c +++ b/src/backend/libpq/be-secure-common.c @@ -118,6 +118,7 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, buf[--len] = '\0'; error: + explicit_bzero(buf, size); pfree(command.data); return len; } diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 6cd4cfed0a..0062a4a426 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -201,6 +201,9 @@ /* Define to 1 if you have the <editline/readline.h> header file. */ #undef HAVE_EDITLINE_READLINE_H +/* Define to 1 if you have the `explicit_bzero' function. */ +#undef HAVE_EXPLICIT_BZERO + /* Define to 1 if you have the `fdatasync' function. */ #undef HAVE_FDATASYNC diff --git a/src/include/port.h b/src/include/port.h index b5c03d912b..7c8b5138ba 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -381,6 +381,10 @@ extern int isinf(double x); #endif /* __clang__ && !__cplusplus */ #endif /* !HAVE_ISINF */ +#ifndef HAVE_EXPLICIT_BZERO +#define explicit_bzero(b, len) memset(b, 0, len) +#endif + #ifndef HAVE_STRTOF extern float strtof(const char *nptr, char **endptr); #endif diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index c800d7921e..887b8f6775 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -3884,7 +3884,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); } @@ -3918,7 +3921,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) @@ -6935,6 +6941,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; } @@ -6951,6 +6958,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname, } fclose(fp); + explicit_bzero(buf, sizeof(buf)); return NULL; #undef LINELEN base-commit: 1323bfce55109dd54ee164828aab7983d3020a25 -- 2.22.0

view thread (35+ messages)  latest in thread

Message-ID: <2b38e01a-0f7c-33f8-d4a9-edfcf85f9e4b@2ndquadrant.com>
Permalink:  ../2b38e01a-0f7c-33f8-d4a9-edfcf85f9e4b@2ndquadrant.com/
Also on:    postgresql.org/message-id/2b38e01a-0f7c-33f8-d4a9-edfcf85f9e4b@2ndquadrant.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: peter.eisentraut@2ndquadrant.com, tgl@sss.pgh.pa.us
  Subject: Re: using explicit_bzero
  In-Reply-To: <2b38e01a-0f7c-33f8-d4a9-edfcf85f9e4b@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox