aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2015-06-17 08:13:33 -0400
committerNoah Misch <noah@leadboat.com>2015-06-17 08:13:33 -0400
commitb76e76be460a240e99c33f6fb470dd1d5fe01a2a (patch)
tree9bb2248ce31a0900553cb1c2b199f7dc4018ac52 /src/backend/utils/adt/pg_locale.c
parent41d798a139b5c94ad8ce10b192141b5bcc03dda3 (diff)
downloadpostgresql-b76e76be460a240e99c33f6fb470dd1d5fe01a2a.tar.gz
postgresql-b76e76be460a240e99c33f6fb470dd1d5fe01a2a.zip
Detect setlocale(LC_CTYPE, NULL) clobbering previous return values.
POSIX permits setlocale() calls to invalidate any previous setlocale() return values. Commit 5f538ad004aa00cf0881f179f0cde789aad4f47e neglected to account for that. In advance of fixing that bug, switch to failing hard on affected configurations. This is a planned temporary commit to assay buildfarm-represented configurations.
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 4be735e918d..590c7702e7b 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -58,6 +58,7 @@
#include "catalog/pg_collation.h"
#include "catalog/pg_control.h"
#include "mb/pg_wchar.h"
+#include "utils/builtins.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
@@ -148,6 +149,7 @@ pg_perm_setlocale(int category, const char *locale)
char *result;
const char *envvar;
char *envbuf;
+ char orig_result[LC_ENV_BUFSIZE];
#ifndef WIN32
result = setlocale(category, locale);
@@ -173,6 +175,7 @@ pg_perm_setlocale(int category, const char *locale)
if (result == NULL)
return result; /* fall out immediately on failure */
+ strlcpy(orig_result, result, sizeof(orig_result));
/*
* Use the right encoding in translated messages. Under ENABLE_NLS, let
@@ -231,6 +234,17 @@ pg_perm_setlocale(int category, const char *locale)
}
snprintf(envbuf, LC_ENV_BUFSIZE - 1, "%s=%s", envvar, result);
+ if (strcmp(orig_result, result) != 0)
+ {
+ char hex[2 * LC_ENV_BUFSIZE + 1];
+ unsigned hexlen;
+
+ hexlen =
+ hex_encode(result, Min(1 + strlen(result), LC_ENV_BUFSIZE), hex);
+ hex[hexlen] = '\0';
+ elog(FATAL, "setlocale() result %s clobbered to 0x%s",
+ orig_result, hex);
+ }
if (putenv(envbuf))
return NULL;