postgresql/src/backend
Tom Lane c81062e8e1 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:32 -04:00
..
access Reset properly errno before calling write() 2018-08-05 05:32:37 +09:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Add table relcache invalidation to index builds. 2018-08-03 14:44:38 -07:00
commands Don't record FDW user mappings as members of extensions. 2018-08-07 16:33:08 -04:00
executor Fix misc typos, mostly in comments. 2018-07-18 16:54:54 +03:00
foreign Code review for foreign/custom join pushdown patch. 2015-05-10 14:36:36 -04:00
lib Revert "Permit dump/reload of not-too-large >1GB tuples" 2016-12-06 12:45:49 -03:00
libpq Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:32 -04:00
main Install Windows crash dump handler before all else. 2017-11-12 14:31:04 -08:00
nodes Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:50 -04:00
optimizer Fix print of Path nodes when using OPTIMIZER_DEBUG 2018-07-19 09:55:32 +09:00
parser Fix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *. 2018-08-04 19:38:59 -04:00
po Translation updates 2018-08-06 19:35:42 +02:00
port Fix and improve pg_atomic_flag fallback implementation. 2018-04-06 20:02:12 -07:00
postmaster Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:32 -04:00
regex Fix regexport.c to behave sanely with lookaround constraints. 2017-04-13 17:18:35 -04:00
replication Don't run atexit callbacks in quickdie signal handlers. 2018-08-08 19:09:35 +03:00
rewrite Fix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *. 2018-08-04 19:38:59 -04:00
snowball Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
storage Fix inadequate buffer locking in FSM and VM page re-initialization. 2018-07-13 11:53:15 -04:00
tcop Don't run atexit callbacks in quickdie signal handlers. 2018-08-08 19:09:35 +03:00
tsearch Fix bogus affix-merging code. 2018-04-12 18:39:51 -04:00
utils Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:32 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:45:38 -04:00
nls.mk Translation updates 2015-02-01 23:23:40 -05:00