pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Replace a bunch more uses of strncpy() with safer coding. 6+ messages / 1 participants [nested] [flat]
* pgsql: Replace a bunch more uses of strncpy() with safer coding. @ 2015-01-24 18:06 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-01-24 18:06 UTC (permalink / raw) To: pgsql-committers Replace a bunch more uses of strncpy() with safer coding. strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches. Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/586dd5d6a5d59e406bc8032bb52625ffb904311c Modified Files -------------- contrib/fuzzystrmatch/dmetaphone.c | 2 +- contrib/isn/isn.c | 8 ++++---- contrib/pg_trgm/trgm_regexp.c | 2 +- contrib/pgbench/pgbench.c | 2 +- contrib/pgcrypto/crypt-des.c | 3 +-- contrib/xml2/xpath.c | 2 +- src/backend/libpq/hba.c | 7 +++++-- src/backend/postmaster/pgstat.c | 2 +- src/backend/regex/regerror.c | 2 +- src/backend/replication/logical/logical.c | 4 +--- src/backend/replication/slot.c | 3 +-- src/backend/utils/adt/datetime.c | 2 +- src/backend/utils/adt/name.c | 2 +- src/backend/utils/adt/varlena.c | 2 +- src/backend/utils/error/elog.c | 2 +- src/bin/initdb/initdb.c | 4 ++-- src/bin/pg_dump/pg_backup_archiver.c | 2 +- src/bin/pg_dump/pg_backup_db.c | 2 +- src/interfaces/ecpg/ecpglib/execute.c | 14 +++++++------- src/interfaces/ecpg/ecpglib/prepare.c | 2 +- src/interfaces/ecpg/pgtypeslib/datetime.c | 10 +++++----- src/interfaces/ecpg/pgtypeslib/dt_common.c | 2 +- src/interfaces/ecpg/test/pg_regress_ecpg.c | 3 +-- src/interfaces/libpq/fe-exec.c | 6 +++--- src/interfaces/libpq/fe-protocol2.c | 1 + src/interfaces/libpq/fe-secure-openssl.c | 8 ++++---- 26 files changed, 49 insertions(+), 50 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Replace a bunch more uses of strncpy() with safer coding. @ 2015-01-24 18:06 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-01-24 18:06 UTC (permalink / raw) To: pgsql-committers Replace a bunch more uses of strncpy() with safer coding. strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches. Branch ------ REL9_4_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/d51d4ff311d01de8521acedb0a6f7c242648a231 Modified Files -------------- src/interfaces/libpq/fe-secure.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Replace a bunch more uses of strncpy() with safer coding. @ 2015-01-24 18:06 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-01-24 18:06 UTC (permalink / raw) To: pgsql-committers Replace a bunch more uses of strncpy() with safer coding. strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches. Branch ------ REL9_3_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/7240f9200c96cb58fdf96d39b46dfe56b4965a58 Modified Files -------------- src/interfaces/libpq/fe-secure.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Replace a bunch more uses of strncpy() with safer coding. @ 2015-01-24 18:06 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-01-24 18:06 UTC (permalink / raw) To: pgsql-committers Replace a bunch more uses of strncpy() with safer coding. strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches. Branch ------ REL9_2_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/502e5f9c3608c4620eb3044ad5321d61a1f9f646 Modified Files -------------- src/interfaces/libpq/fe-secure.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Replace a bunch more uses of strncpy() with safer coding. @ 2015-01-24 18:06 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-01-24 18:06 UTC (permalink / raw) To: pgsql-committers Replace a bunch more uses of strncpy() with safer coding. strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches. Branch ------ REL9_1_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/b00a0885918f163ac182d04d9852ca0576515037 Modified Files -------------- src/interfaces/libpq/fe-secure.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Replace a bunch more uses of strncpy() with safer coding. @ 2015-01-24 18:06 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-01-24 18:06 UTC (permalink / raw) To: pgsql-committers Replace a bunch more uses of strncpy() with safer coding. strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches. Branch ------ REL9_0_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/3a3ee655c3e1ce8fce26698bfd9601d85947da06 Modified Files -------------- src/interfaces/libpq/fe-secure.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2015-01-24 18:06 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2015-01-24 18:06 pgsql: Replace a bunch more uses of strncpy() with safer coding. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-24 18:06 pgsql: Replace a bunch more uses of strncpy() with safer coding. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-24 18:06 pgsql: Replace a bunch more uses of strncpy() with safer coding. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-24 18:06 pgsql: Replace a bunch more uses of strncpy() with safer coding. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-24 18:06 pgsql: Replace a bunch more uses of strncpy() with safer coding. Tom Lane <tgl@sss.pgh.pa.us> 2015-01-24 18:06 pgsql: Replace a bunch more uses of strncpy() with safer coding. 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