Prevent potential overruns of fixed-size buffers.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 17 Feb 2014 16:20:35 +0000 (11:20 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 17 Feb 2014 16:20:35 +0000 (11:20 -0500)
commit45bf2404a2f586a35e8647890a7d5917b787a623
tree74885ce0a3dec6e273f914ac6b1853aa9af2daaa
parent2c3203e18551343db11ed9d372cd2a25d65d3f35
Prevent potential overruns of fixed-size buffers.

Coverity identified a number of places in which it couldn't prove that a
string being copied into a fixed-size buffer would fit.  We believe that
most, perhaps all of these are in fact safe, or are copying data that is
coming from a trusted source so that any overrun is not really a security
issue.  Nonetheless it seems prudent to forestall any risk by using
strlcpy() and similar functions.

Fixes by Peter Eisentraut and Jozef Mlich based on Coverity reports.

In addition, fix a potential null-pointer-dereference crash in
contrib/chkpass.  The crypt(3) function is defined to return NULL on
failure, but chkpass.c didn't check for that before using the result.
The main practical case in which this could be an issue is if libc is
configured to refuse to execute unapproved hashing algorithms (e.g.,
"FIPS mode").  This ideally should've been a separate commit, but
since it touches code adjacent to one of the buffer overrun changes,
I included it in this commit to avoid last-minute merge issues.
This issue was reported by Honza Horak.

Security: CVE-2014-0065 for buffer overruns, CVE-2014-0066 for crypt()
12 files changed:
contrib/chkpass/chkpass.c
contrib/pg_standby/pg_standby.c
src/backend/access/transam/xlog.c
src/backend/tsearch/spell.c
src/backend/utils/adt/datetime.c
src/bin/initdb/initdb.c
src/interfaces/ecpg/preproc/pgc.l
src/interfaces/libpq/fe-protocol2.c
src/interfaces/libpq/fe-protocol3.c
src/port/exec.c
src/test/regress/pg_regress.c
src/timezone/pgtz.c