postgresql/src
Tom Lane cc4f6b7786 Clean up assorted misuses of snprintf()'s result value.
Fix a small number of places that were testing the result of snprintf()
but doing so incorrectly.  The right test for buffer overrun, per C99,
is "result >= bufsize" not "result > bufsize".  Some places were also
checking for failure with "result == -1", but the standard only says
that a negative value is delivered on failure.

(Note that this only makes these places correct if snprintf() delivers
C99-compliant results.  But at least now these places are consistent
with all the other places where we assume that.)

Also, make psql_start_test() and isolation_start_test() check for
buffer overrun while constructing their shell commands.  There seems
like a higher risk of overrun, with more severe consequences, here
than there is for the individual file paths that are made elsewhere
in the same functions, so this seemed like a worthwhile change.

Also fix guc.c's do_serialize() to initialize errno = 0 before
calling vsnprintf.  In principle, this should be unnecessary because
vsnprintf should have set errno if it returns a failure indication ...
but the other two places this coding pattern is cribbed from don't
assume that, so let's be consistent.

These errors are all very old, so back-patch as appropriate.  I think
that only the shell command overrun cases are even theoretically
reachable in practice, but there's not much point in erroneous error
checks.

Discussion: https://postgr.es/m/17245.1534289329@sss.pgh.pa.us
2018-08-15 16:29:31 -04:00
..
backend Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:31 -04:00
bin pg_upgrade: fix shutdown check for standby servers 2018-08-14 17:19:02 -04:00
common Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:31 -04:00
fe_utils Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
include Remove duplicate function declarations. 2018-08-14 14:25:14 -04:00
interfaces Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:31 -04:00
makefiles Provide for contrib and pgxs modules to install include files. 2018-07-31 20:07:39 +01:00
pl Provide plpgsql tests for cases involving record field changes. 2018-07-26 18:18:37 -04:00
port Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:31 -04:00
template Force "restrict" not to be used when compiling with xlc. 2017-10-13 12:15:06 -07:00
test Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:31 -04:00
timezone Update time zone data files to tzdata release 2018e. 2018-05-09 13:56:22 -04:00
tools Provide for contrib and pgxs modules to install include files. 2018-07-31 20:07:39 +01:00
tutorial Deduplicate "invalid input syntax" messages for various types. 2018-07-22 14:58:01 -07:00
.gitignore
DEVELOPERS
Makefile Fix partial-build problems introduced by having more generated headers. 2018-04-09 16:42:10 -04:00
Makefile.global.in Ensure we build generated headers at the start of some more cases. 2018-07-30 18:04:39 -04:00
Makefile.shlib Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-04-03 16:26:05 -04:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00