@@ -854,6 +854,64 @@ IsoLocaleName(const char *winlocname)
854
854
#endif /* WIN32 && LC_MESSAGES */
855
855
856
856
857
+ /*
858
+ * Detect aging strxfrm() implementations that, in a subset of locales, write
859
+ * past the specified buffer length. Affected users must update OS packages
860
+ * before using PostgreSQL 9.5 or later.
861
+ *
862
+ * Assume that the bug can come and go from one postmaster startup to another
863
+ * due to physical replication among diverse machines. Assume that the bug's
864
+ * presence will not change during the life of a particular postmaster. Given
865
+ * those assumptions, call this no less than once per postmaster startup per
866
+ * LC_COLLATE setting used. No known-affected system offers strxfrm_l(), so
867
+ * there is no need to consider pg_collation locales.
868
+ */
869
+ void
870
+ check_strxfrm_bug (void )
871
+ {
872
+ char buf [32 ];
873
+ const int canary = 0x7F ;
874
+ bool ok = true;
875
+
876
+ /*
877
+ * Given a two-byte ASCII string and length limit 7, 8 or 9, Solaris 10
878
+ * 05/08 returns 18 and modifies 10 bytes. It respects limits above or
879
+ * below that range.
880
+ *
881
+ * The bug is present in Solaris 8 as well; it is absent in Solaris 10
882
+ * 01/13 and Solaris 11.2. Affected locales include is_IS.ISO8859-1,
883
+ * en_US.UTF-8, en_US.ISO8859-1, and ru_RU.KOI8-R. Unaffected locales
884
+ * include de_DE.UTF-8, de_DE.ISO8859-1, zh_TW.UTF-8, and C.
885
+ */
886
+ buf [7 ] = canary ;
887
+ (void ) strxfrm (buf , "ab" , 7 );
888
+ if (buf [7 ] != canary )
889
+ ok = false;
890
+
891
+ /*
892
+ * illumos bug #1594 was present in the source tree from 2010-10-11 to
893
+ * 2012-02-01. Given an ASCII string of any length and length limit 1,
894
+ * affected systems ignore the length limit and modify a number of bytes
895
+ * one less than the return value. The problem inputs for this bug do not
896
+ * overlap those for the Solaris bug, hence a distinct test.
897
+ *
898
+ * Affected systems include smartos-20110926T021612Z. Affected locales
899
+ * include en_US.ISO8859-1 and en_US.UTF-8. Unaffected locales include C.
900
+ */
901
+ buf [1 ] = canary ;
902
+ (void ) strxfrm (buf , "a" , 1 );
903
+ if (buf [1 ] != canary )
904
+ ok = false;
905
+
906
+ if (!ok )
907
+ ereport (ERROR ,
908
+ (errcode (ERRCODE_SYSTEM_ERROR ),
909
+ errmsg_internal ("strxfrm(), in locale \"%s\", writes past the specified array length" ,
910
+ setlocale (LC_COLLATE , NULL )),
911
+ errhint ("Apply system library package updates." )));
912
+ }
913
+
914
+
857
915
/*
858
916
* Cache mechanism for collation information.
859
917
*
0 commit comments