Remove obsolete defense against strxfrm() bugs.
authorThomas Munro <[email protected]>
Thu, 20 Apr 2023 01:15:23 +0000 (13:15 +1200)
committerThomas Munro <[email protected]>
Thu, 20 Apr 2023 01:20:14 +0000 (13:20 +1200)
Old versions of Solaris and illumos had buffer overrun bugs in their
strxfrm() implementations.  The bugs were fixed more than a decade ago
and the relevant releases are long out of vendor support.  It's time to
remove the defense added by commit be8b06c3.

Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CA+hUKGJ-ZPJwKHVLbqye92-ZXeLoCHu5wJL6L6HhNP7FkJ=meA@mail.gmail.com

src/backend/main/main.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/init/postinit.c
src/include/utils/pg_locale.h

index 43978fd359c8710ef26c33b6baa874dc430ebc95..ed11e8be7fab7b9cb434d74356aea09a2953649c 100644 (file)
@@ -137,8 +137,6 @@ main(int argc, char *argv[])
     */
    unsetenv("LC_ALL");
 
-   check_strxfrm_bug();
-
    /*
     * Catch standard options before doing much else, in particular before we
     * insist on not being root.
index 092b620673f87e6e856c52bd00ea76177ad69cb7..51df570ce99612d580d8cc460e98836d22fc189a 100644 (file)
@@ -1162,64 +1162,6 @@ IsoLocaleName(const char *winlocname)
 #endif                         /* WIN32 && LC_MESSAGES */
 
 
-/*
- * Detect aging strxfrm() implementations that, in a subset of locales, write
- * past the specified buffer length.  Affected users must update OS packages
- * before using PostgreSQL 9.5 or later.
- *
- * Assume that the bug can come and go from one postmaster startup to another
- * due to physical replication among diverse machines.  Assume that the bug's
- * presence will not change during the life of a particular postmaster.  Given
- * those assumptions, call this no less than once per postmaster startup per
- * LC_COLLATE setting used.  No known-affected system offers strxfrm_l(), so
- * there is no need to consider pg_collation locales.
- */
-void
-check_strxfrm_bug(void)
-{
-   char        buf[32];
-   const int   canary = 0x7F;
-   bool        ok = true;
-
-   /*
-    * Given a two-byte ASCII string and length limit 7, 8 or 9, Solaris 10
-    * 05/08 returns 18 and modifies 10 bytes.  It respects limits above or
-    * below that range.
-    *
-    * The bug is present in Solaris 8 as well; it is absent in Solaris 10
-    * 01/13 and Solaris 11.2.  Affected locales include is_IS.ISO8859-1,
-    * en_US.UTF-8, en_US.ISO8859-1, and ru_RU.KOI8-R.  Unaffected locales
-    * include de_DE.UTF-8, de_DE.ISO8859-1, zh_TW.UTF-8, and C.
-    */
-   buf[7] = canary;
-   (void) strxfrm(buf, "ab", 7);
-   if (buf[7] != canary)
-       ok = false;
-
-   /*
-    * illumos bug #1594 was present in the source tree from 2010-10-11 to
-    * 2012-02-01.  Given an ASCII string of any length and length limit 1,
-    * affected systems ignore the length limit and modify a number of bytes
-    * one less than the return value.  The problem inputs for this bug do not
-    * overlap those for the Solaris bug, hence a distinct test.
-    *
-    * Affected systems include smartos-20110926T021612Z.  Affected locales
-    * include en_US.ISO8859-1 and en_US.UTF-8.  Unaffected locales include C.
-    */
-   buf[1] = canary;
-   (void) strxfrm(buf, "a", 1);
-   if (buf[1] != canary)
-       ok = false;
-
-   if (!ok)
-       ereport(ERROR,
-               (errcode(ERRCODE_SYSTEM_ERROR),
-                errmsg_internal("strxfrm(), in locale \"%s\", writes past the specified array length",
-                                setlocale(LC_COLLATE, NULL)),
-                errhint("Apply system library package updates.")));
-}
-
-
 /*
  * Cache mechanism for collation information.
  *
index 5af87a7868380ff554e09c84cc7392db5efd459f..53420f4974fc1047e6944198be111cad4848b6d9 100644 (file)
@@ -487,8 +487,6 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
    SetConfigOption("lc_collate", collate, PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT);
    SetConfigOption("lc_ctype", ctype, PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT);
 
-   check_strxfrm_bug();
-
    ReleaseSysCache(tup);
 }
 
index 8c095abc5241295983460440112e0f23217a05cd..03ab5982158c9e7f270377d81d38e89ded2670d6 100644 (file)
@@ -53,7 +53,6 @@ extern PGDLLIMPORT bool   database_ctype_is_c;
 
 extern bool check_locale(int category, const char *locale, char **canonname);
 extern char *pg_perm_setlocale(int category, const char *locale);
-extern void check_strxfrm_bug(void);
 
 extern bool lc_collate_is_c(Oid collation);
 extern bool lc_ctype_is_c(Oid collation);