forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitadbb27a
committed
Reject non-ASCII locale names.
Commitbf03cfd started scanning all available BCP 47 locale names onWindows. This caused an abort/crash in the Windows runtime library ifthe default locale name contained non-ASCII characters, because of ouruse of the setlocale() save/restore pattern with "char" strings. Afterswitching to another locale with a different encoding, the saved namecould no longer be understood, and setlocale() would abort."Turkish_Türkiye.1254" is the example from recent reports, but there areother examples of countries and languages with non-ASCII characters intheir names, and they appear in Windows' (old style) locale names.To defend against this:1. In initdb, reject non-ASCII locale names given explicity on thecommand line, or returned by the operating system environment withsetlocale(..., ""), or "canonicalized" by the operating system when weset it.2. In initdb only, perform the save-and-restore with Windows'non-standard wchar_t variant of setlocale(), so that it is not subjectto round trip failures stemming from char string encoding confusion.3. In the backend, we don't have to worry about the save-and-restoreproblem because we have already vetted the defaults, so we just have tomake sure that CREATE DATABASE also rejects non-ASCII names in any newdatabases. SET lc_XXX doesn't suffer from the problem, but the banapplies to it too because it uses check_locale(). CREATE COLLATIONdoesn't suffer from the problem either, but it doesn't usecheck_locale() so it is not included in the new ban for now, to minimizethe change.Anyone who encounters the new error message should either create a newduplicated locale with an ASCII-only name using Windows Locale Builder,or consider using BCP 47 names like "tr-TR". Users already couldn'tinitialize a cluster with "Turkish_Türkiye.1254" on PostgreSQL 16+, butthe new failure mode is an error message that explains why, instead of acrash.Back-patch to 16, wherebf03cfd landed. Older versions are affectedin theory too, but only 16 and later are causing crash reports.Reviewed-by: Andrew Dunstan <andrew@dunslane.net> (the idea, not the patch)Reported-by: Haifang Wang (Centific Technologies Inc) <v-haiwang@microsoft.com>Discussion:https://postgr.es/m/PH8PR21MB3902F334A3174C54058F792CE5182%40PH8PR21MB3902.namprd21.prod.outlook.com1 parentf22e84d commitadbb27a
2 files changed
+93
-17
lines changedLines changed: 23 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
58 | 58 |
| |
59 | 59 |
| |
60 | 60 |
| |
| 61 | + | |
61 | 62 |
| |
62 | 63 |
| |
63 | 64 |
| |
| |||
341 | 342 |
| |
342 | 343 |
| |
343 | 344 |
| |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
344 | 355 |
| |
345 | 356 |
| |
346 | 357 |
| |
| |||
363 | 374 |
| |
364 | 375 |
| |
365 | 376 |
| |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
366 | 389 |
| |
367 | 390 |
| |
368 | 391 |
| |
|
Lines changed: 70 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
340 | 340 |
| |
341 | 341 |
| |
342 | 342 |
| |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
343 | 398 |
| |
344 | 399 |
| |
345 | 400 |
| |
| |||
2074 | 2129 |
| |
2075 | 2130 |
| |
2076 | 2131 |
| |
2077 |
| - | |
| 2132 | + | |
2078 | 2133 |
| |
2079 | 2134 |
| |
2080 | 2135 |
| |
2081 | 2136 |
| |
2082 | 2137 |
| |
2083 |
| - | |
2084 |
| - | |
2085 |
| - | |
2086 |
| - | |
| 2138 | + | |
2087 | 2139 |
| |
2088 | 2140 |
| |
2089 | 2141 |
| |
| |||
2094 | 2146 |
| |
2095 | 2147 |
| |
2096 | 2148 |
| |
2097 |
| - | |
2098 |
| - | |
| 2149 | + | |
2099 | 2150 |
| |
2100 | 2151 |
| |
2101 | 2152 |
| |
| |||
2132 | 2183 |
| |
2133 | 2184 |
| |
2134 | 2185 |
| |
2135 |
| - | |
| 2186 | + | |
2136 | 2187 |
| |
2137 | 2188 |
| |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
2138 | 2193 |
| |
2139 | 2194 |
| |
2140 | 2195 |
| |
2141 |
| - | |
2142 |
| - | |
2143 |
| - | |
2144 |
| - | |
2145 |
| - | |
2146 |
| - | |
| 2196 | + | |
2147 | 2197 |
| |
2148 | 2198 |
| |
2149 | 2199 |
| |
| |||
2157 | 2207 |
| |
2158 | 2208 |
| |
2159 | 2209 |
| |
2160 |
| - | |
2161 |
| - | |
2162 |
| - | |
| 2210 | + | |
2163 | 2211 |
| |
2164 | 2212 |
| |
2165 | 2213 |
| |
| |||
2183 | 2231 |
| |
2184 | 2232 |
| |
2185 | 2233 |
| |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
2186 | 2239 |
| |
2187 | 2240 |
| |
2188 | 2241 |
| |
|
0 commit comments
Comments
(0)