pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Clean up assorted misuses of snprintf()'s result value. 7+ messages / 1 participants [nested] [flat]
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c81062e8e12f4186a4d7d95e07541883f4e1d87e Modified Files -------------- src/backend/libpq/ip.c | 6 +++--- src/backend/postmaster/pgstat.c | 2 +- src/backend/utils/misc/guc.c | 2 ++ src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 24 ++++++++++++++++++------ src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 26 +++++++++++++++++++------- 8 files changed, 46 insertions(+), 20 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL9_3_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3531365de5e868224c70cd568384f453056f7646 Modified Files -------------- src/backend/libpq/ip.c | 6 +++--- src/backend/postmaster/pgstat.c | 2 +- src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 22 +++++++++++++++++----- src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 26 +++++++++++++++++++------- 7 files changed, 43 insertions(+), 19 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6101bc2f459c3c5f4e8386083edb79443075b54e Modified Files -------------- src/backend/postmaster/pgstat.c | 2 +- src/backend/utils/misc/guc.c | 2 ++ src/common/ip.c | 6 +++--- src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 24 ++++++++++++++++++------ src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 28 ++++++++++++++++++++-------- 8 files changed, 47 insertions(+), 21 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d7ed4eea539dbd6bf89163213ea6068b4ef0fe11 Modified Files -------------- src/backend/postmaster/pgstat.c | 2 +- src/backend/utils/misc/guc.c | 2 ++ src/common/ip.c | 6 +++--- src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 24 ++++++++++++++++++------ src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 28 ++++++++++++++++++++-------- 8 files changed, 47 insertions(+), 21 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL9_4_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d371efb39c33f79ad5f6741d76bfae54df21eb55 Modified Files -------------- src/backend/libpq/ip.c | 6 +++--- src/backend/postmaster/pgstat.c | 2 +- src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 24 ++++++++++++++++++------ src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 26 +++++++++++++++++++------- 7 files changed, 44 insertions(+), 20 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/cc4f6b77861803be99dfc17a38052035a0af5ae6 Modified Files -------------- src/backend/postmaster/pgstat.c | 2 +- src/backend/utils/misc/guc.c | 2 ++ src/common/ip.c | 6 +++--- src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 24 ++++++++++++++++++------ src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 28 ++++++++++++++++++++-------- 8 files changed, 47 insertions(+), 21 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Clean up assorted misuses of snprintf()'s result value. @ 2018-08-15 20:29 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2018-08-15 20:29 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c182c1e0b895c8e6baf7c5a9d3cd98307f420168 Modified Files -------------- src/backend/libpq/ip.c | 6 +++--- src/backend/postmaster/pgstat.c | 2 +- src/backend/utils/misc/guc.c | 2 ++ src/interfaces/ecpg/pgtypeslib/common.c | 2 +- src/port/getaddrinfo.c | 2 +- src/test/isolation/isolation_main.c | 24 ++++++++++++++++++------ src/test/regress/pg_regress.c | 2 +- src/test/regress/pg_regress_main.c | 26 +++++++++++++++++++------- 8 files changed, 46 insertions(+), 20 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2018-08-15 20:29 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us> 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us> 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us> 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us> 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us> 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us> 2018-08-15 20:29 pgsql: Clean up assorted misuses of snprintf()'s result value. Tom Lane <tgl@sss.pgh.pa.us>
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