diff options
author | Stephen Frost <sfrost@snowman.net> | 2018-09-28 19:04:50 -0400 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2018-09-28 19:04:50 -0400 |
commit | 8bddc864000f56d396621d4ad0f13e8e1872ddf5 (patch) | |
tree | 787fd20caa7cb852d9468a6d09aae91760643198 /src/common/string.c | |
parent | 2b04dfc4724970231ac338aa71e529c823fc5ff6 (diff) | |
download | postgresql-8bddc864000f56d396621d4ad0f13e8e1872ddf5.tar.gz postgresql-8bddc864000f56d396621d4ad0f13e8e1872ddf5.zip |
Add application_name to connection authorized msg
The connection authorized message has quite a bit of useful information
in it, but didn't include the application_name (when provided), so let's
add that as it can be very useful.
Note that at the point where we're emitting the connection authorized
message, we haven't processed GUCs, so it's not possible to get this by
using log_line_prefix (which pulls from the GUC). There's also
something to be said for having this included in the connection
authorized message and then not needing to repeat it for every line, as
having it in log_line_prefix would do.
The GUC cleans the application name to pure-ascii, so do that here too,
but pull out the logic for cleaning up a string into its own function
in common and re-use it from those places, and check_cluster_name which
was doing the same thing.
Author: Don Seiler <don@seiler.us>
Discussion: https://postgr.es/m/CAHJZqBB_Pxv8HRfoh%2BAB4KxSQQuPVvtYCzMg7woNR3r7dfmopw%40mail.gmail.com
Diffstat (limited to 'src/common/string.c')
-rw-r--r-- | src/common/string.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/string.c b/src/common/string.c index 3260d37a84e..499e81811a6 100644 --- a/src/common/string.c +++ b/src/common/string.c @@ -56,3 +56,37 @@ strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base) errno = ERANGE; return (int) val; } + + +/* + * pg_clean_ascii -- Replace any non-ASCII chars with a '?' char + * + * Modifies the string passed in which must be '\0'-terminated. + * + * This function exists specifically to deal with filtering out + * non-ASCII characters in a few places where the client can provide an almost + * arbitrary string (and it isn't checked to ensure it's a valid username or + * database name or similar) and we don't want to have control characters or other + * things ending up in the log file where server admins might end up with a + * messed up terminal when looking at them. + * + * In general, this function should NOT be used- instead, consider how to handle + * the string without needing to filter out the non-ASCII characters. + * + * Ultimately, we'd like to improve the situation to not require stripping out + * all non-ASCII but perform more intelligent filtering which would allow UTF or + * similar, but it's unclear exactly what we should allow, so stick to ASCII only + * for now. + */ +void +pg_clean_ascii(char *str) +{ + /* Only allow clean ASCII chars in the string */ + char *p; + + for (p = str; *p != '\0'; p++) + { + if (*p < 32 || *p > 126) + *p = '?'; + } +} |