pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix incautious handling of possibly-miscoded strings in client c 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix incautious handling of possibly-miscoded strings in client c @ 2021-06-07 18:15 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2021-06-07 18:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incautious handling of possibly-miscoded strings in client code. An incorrectly-encoded multibyte character near the end of a string could cause various processing loops to run past the string's terminating NUL, with results ranging from no detectable issue to a program crash, depending on what happens to be in the following memory. This isn't an issue in the server, because we take care to verify the encoding of strings before doing any interesting processing on them. However, that lack of care leaked into client-side code which shouldn't assume that anyone has validated the encoding of its input. Although this is certainly a bug worth fixing, the PG security team elected not to regard it as a security issue, primarily because any untrusted text should be sanitized by PQescapeLiteral or the like before being incorporated into a SQL or psql command. (If an app fails to do so, the same technique can be used to cause SQL injection, with probably much more dire consequences than a mere client-program crash.) Those functions were already made proof against this class of problem, cf CVE-2006-2313. To fix, invent PQmblenBounded() which is like PQmblen() except it won't return more than the number of bytes remaining in the string. In HEAD we can make this a new libpq function, as PQmblen() is. It seems imprudent to change libpq's API in stable branches though, so in the back branches define PQmblenBounded as a macro in the files that need it. (Note that just changing PQmblen's behavior would not be a good idea; notably, it would completely break the escaping functions' defense against this exact problem. So we just want a version for those callers that don't have any better way of handling this issue.) Per private report from houjingyi. Back-patch to all supported branches. Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/42f94f56bf9559f0a3cf5f3ffde50655834694ee Modified Files -------------- src/bin/psql/common.c | 26 +++++++++++++------------- src/bin/psql/psqlscanslash.l | 2 +- src/bin/psql/stringutils.c | 6 +++--- src/bin/psql/tab-complete.c | 2 +- src/bin/scripts/common.c | 2 +- src/common/jsonapi.c | 6 +++--- src/common/wchar.c | 15 +++++++++++++++ src/fe_utils/print.c | 3 +++ src/fe_utils/string_utils.c | 9 +++------ src/include/mb/pg_wchar.h | 1 + src/interfaces/libpq/exports.txt | 1 + src/interfaces/libpq/fe-misc.c | 19 +++++++++++++++++-- src/interfaces/libpq/fe-print.c | 2 +- src/interfaces/libpq/fe-protocol3.c | 4 ++-- src/interfaces/libpq/libpq-fe.h | 3 +++ 15 files changed, 68 insertions(+), 33 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix incautious handling of possibly-miscoded strings in client c @ 2021-06-07 18:15 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2021-06-07 18:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incautious handling of possibly-miscoded strings in client code. An incorrectly-encoded multibyte character near the end of a string could cause various processing loops to run past the string's terminating NUL, with results ranging from no detectable issue to a program crash, depending on what happens to be in the following memory. This isn't an issue in the server, because we take care to verify the encoding of strings before doing any interesting processing on them. However, that lack of care leaked into client-side code which shouldn't assume that anyone has validated the encoding of its input. Although this is certainly a bug worth fixing, the PG security team elected not to regard it as a security issue, primarily because any untrusted text should be sanitized by PQescapeLiteral or the like before being incorporated into a SQL or psql command. (If an app fails to do so, the same technique can be used to cause SQL injection, with probably much more dire consequences than a mere client-program crash.) Those functions were already made proof against this class of problem, cf CVE-2006-2313. To fix, invent PQmblenBounded() which is like PQmblen() except it won't return more than the number of bytes remaining in the string. In HEAD we can make this a new libpq function, as PQmblen() is. It seems imprudent to change libpq's API in stable branches though, so in the back branches define PQmblenBounded as a macro in the files that need it. (Note that just changing PQmblen's behavior would not be a good idea; notably, it would completely break the escaping functions' defense against this exact problem. So we just want a version for those callers that don't have any better way of handling this issue.) Per private report from houjingyi. Back-patch to all supported branches. Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5b64368742b5cdf73395bd5ddd66b5edcbc20823 Modified Files -------------- src/bin/psql/common.c | 28 +++++++++++++++------------- src/bin/psql/psqlscanslash.l | 4 +++- src/bin/psql/stringutils.c | 8 +++++--- src/bin/psql/tab-complete.c | 4 +++- src/bin/scripts/common.c | 4 +++- src/common/jsonapi.c | 6 +++--- src/common/wchar.c | 15 +++++++++++++++ src/fe_utils/print.c | 3 +++ src/include/mb/pg_wchar.h | 1 + src/interfaces/libpq/fe-print.c | 3 ++- src/interfaces/libpq/fe-protocol3.c | 6 ++++-- 11 files changed, 57 insertions(+), 25 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix incautious handling of possibly-miscoded strings in client c @ 2021-06-07 18:15 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2021-06-07 18:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incautious handling of possibly-miscoded strings in client code. An incorrectly-encoded multibyte character near the end of a string could cause various processing loops to run past the string's terminating NUL, with results ranging from no detectable issue to a program crash, depending on what happens to be in the following memory. This isn't an issue in the server, because we take care to verify the encoding of strings before doing any interesting processing on them. However, that lack of care leaked into client-side code which shouldn't assume that anyone has validated the encoding of its input. Although this is certainly a bug worth fixing, the PG security team elected not to regard it as a security issue, primarily because any untrusted text should be sanitized by PQescapeLiteral or the like before being incorporated into a SQL or psql command. (If an app fails to do so, the same technique can be used to cause SQL injection, with probably much more dire consequences than a mere client-program crash.) Those functions were already made proof against this class of problem, cf CVE-2006-2313. To fix, invent PQmblenBounded() which is like PQmblen() except it won't return more than the number of bytes remaining in the string. In HEAD we can make this a new libpq function, as PQmblen() is. It seems imprudent to change libpq's API in stable branches though, so in the back branches define PQmblenBounded as a macro in the files that need it. (Note that just changing PQmblen's behavior would not be a good idea; notably, it would completely break the escaping functions' defense against this exact problem. So we just want a version for those callers that don't have any better way of handling this issue.) Per private report from houjingyi. Back-patch to all supported branches. Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/fc896f45d6d859d9da52106cf42dc01dce88c224 Modified Files -------------- src/bin/psql/common.c | 28 +++++++++++++++------------- src/bin/psql/psqlscanslash.l | 4 +++- src/bin/psql/stringutils.c | 8 +++++--- src/bin/psql/tab-complete.c | 4 +++- src/bin/scripts/common.c | 4 +++- src/fe_utils/print.c | 3 +++ src/interfaces/libpq/fe-print.c | 3 ++- src/interfaces/libpq/fe-protocol3.c | 6 ++++-- 8 files changed, 38 insertions(+), 22 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix incautious handling of possibly-miscoded strings in client c @ 2021-06-07 18:15 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2021-06-07 18:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incautious handling of possibly-miscoded strings in client code. An incorrectly-encoded multibyte character near the end of a string could cause various processing loops to run past the string's terminating NUL, with results ranging from no detectable issue to a program crash, depending on what happens to be in the following memory. This isn't an issue in the server, because we take care to verify the encoding of strings before doing any interesting processing on them. However, that lack of care leaked into client-side code which shouldn't assume that anyone has validated the encoding of its input. Although this is certainly a bug worth fixing, the PG security team elected not to regard it as a security issue, primarily because any untrusted text should be sanitized by PQescapeLiteral or the like before being incorporated into a SQL or psql command. (If an app fails to do so, the same technique can be used to cause SQL injection, with probably much more dire consequences than a mere client-program crash.) Those functions were already made proof against this class of problem, cf CVE-2006-2313. To fix, invent PQmblenBounded() which is like PQmblen() except it won't return more than the number of bytes remaining in the string. In HEAD we can make this a new libpq function, as PQmblen() is. It seems imprudent to change libpq's API in stable branches though, so in the back branches define PQmblenBounded as a macro in the files that need it. (Note that just changing PQmblen's behavior would not be a good idea; notably, it would completely break the escaping functions' defense against this exact problem. So we just want a version for those callers that don't have any better way of handling this issue.) Per private report from houjingyi. Back-patch to all supported branches. Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/89a5499ef9e477beb97d742d4df6fc8f601d87d5 Modified Files -------------- src/bin/psql/common.c | 26 ++++++++++++++------------ src/bin/psql/psqlscanslash.l | 4 +++- src/bin/psql/stringutils.c | 8 +++++--- src/bin/psql/tab-complete.c | 4 +++- src/bin/scripts/common.c | 4 +++- src/fe_utils/print.c | 3 +++ src/interfaces/libpq/fe-print.c | 3 ++- src/interfaces/libpq/fe-protocol3.c | 6 ++++-- 8 files changed, 37 insertions(+), 21 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix incautious handling of possibly-miscoded strings in client c @ 2021-06-07 18:15 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2021-06-07 18:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incautious handling of possibly-miscoded strings in client code. An incorrectly-encoded multibyte character near the end of a string could cause various processing loops to run past the string's terminating NUL, with results ranging from no detectable issue to a program crash, depending on what happens to be in the following memory. This isn't an issue in the server, because we take care to verify the encoding of strings before doing any interesting processing on them. However, that lack of care leaked into client-side code which shouldn't assume that anyone has validated the encoding of its input. Although this is certainly a bug worth fixing, the PG security team elected not to regard it as a security issue, primarily because any untrusted text should be sanitized by PQescapeLiteral or the like before being incorporated into a SQL or psql command. (If an app fails to do so, the same technique can be used to cause SQL injection, with probably much more dire consequences than a mere client-program crash.) Those functions were already made proof against this class of problem, cf CVE-2006-2313. To fix, invent PQmblenBounded() which is like PQmblen() except it won't return more than the number of bytes remaining in the string. In HEAD we can make this a new libpq function, as PQmblen() is. It seems imprudent to change libpq's API in stable branches though, so in the back branches define PQmblenBounded as a macro in the files that need it. (Note that just changing PQmblen's behavior would not be a good idea; notably, it would completely break the escaping functions' defense against this exact problem. So we just want a version for those callers that don't have any better way of handling this issue.) Per private report from houjingyi. Back-patch to all supported branches. Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4826fe4c5674b93f3725ce84a091cee521907aae Modified Files -------------- src/bin/psql/common.c | 26 ++++++++++++++------------ src/bin/psql/psqlscanslash.l | 4 +++- src/bin/psql/stringutils.c | 8 +++++--- src/bin/psql/tab-complete.c | 4 +++- src/bin/scripts/common.c | 4 +++- src/fe_utils/print.c | 3 +++ src/interfaces/libpq/fe-print.c | 3 ++- src/interfaces/libpq/fe-protocol3.c | 6 ++++-- 8 files changed, 37 insertions(+), 21 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix incautious handling of possibly-miscoded strings in client c @ 2021-06-07 18:15 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2021-06-07 18:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix incautious handling of possibly-miscoded strings in client code. An incorrectly-encoded multibyte character near the end of a string could cause various processing loops to run past the string's terminating NUL, with results ranging from no detectable issue to a program crash, depending on what happens to be in the following memory. This isn't an issue in the server, because we take care to verify the encoding of strings before doing any interesting processing on them. However, that lack of care leaked into client-side code which shouldn't assume that anyone has validated the encoding of its input. Although this is certainly a bug worth fixing, the PG security team elected not to regard it as a security issue, primarily because any untrusted text should be sanitized by PQescapeLiteral or the like before being incorporated into a SQL or psql command. (If an app fails to do so, the same technique can be used to cause SQL injection, with probably much more dire consequences than a mere client-program crash.) Those functions were already made proof against this class of problem, cf CVE-2006-2313. To fix, invent PQmblenBounded() which is like PQmblen() except it won't return more than the number of bytes remaining in the string. In HEAD we can make this a new libpq function, as PQmblen() is. It seems imprudent to change libpq's API in stable branches though, so in the back branches define PQmblenBounded as a macro in the files that need it. (Note that just changing PQmblen's behavior would not be a good idea; notably, it would completely break the escaping functions' defense against this exact problem. So we just want a version for those callers that don't have any better way of handling this issue.) Per private report from houjingyi. Back-patch to all supported branches. Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ac600c54165631d5266c8aa7c5cb8c96ac589138 Modified Files -------------- src/bin/psql/common.c | 26 ++++++++++++++------------ src/bin/psql/psqlscanslash.l | 4 +++- src/bin/psql/stringutils.c | 8 +++++--- src/bin/psql/tab-complete.c | 4 +++- src/bin/scripts/common.c | 4 +++- src/fe_utils/print.c | 3 +++ src/interfaces/libpq/fe-print.c | 3 ++- src/interfaces/libpq/fe-protocol3.c | 6 ++++-- 8 files changed, 37 insertions(+), 21 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2021-06-07 18:15 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-06-07 18:15 pgsql: Fix incautious handling of possibly-miscoded strings in client c Tom Lane <tgl@sss.pgh.pa.us> 2021-06-07 18:15 pgsql: Fix incautious handling of possibly-miscoded strings in client c Tom Lane <tgl@sss.pgh.pa.us> 2021-06-07 18:15 pgsql: Fix incautious handling of possibly-miscoded strings in client c Tom Lane <tgl@sss.pgh.pa.us> 2021-06-07 18:15 pgsql: Fix incautious handling of possibly-miscoded strings in client c Tom Lane <tgl@sss.pgh.pa.us> 2021-06-07 18:15 pgsql: Fix incautious handling of possibly-miscoded strings in client c Tom Lane <tgl@sss.pgh.pa.us> 2021-06-07 18:15 pgsql: Fix incautious handling of possibly-miscoded strings in client c 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