forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit42f94f5
committed
Fix incautious handling of possibly-miscoded strings in client code.
An incorrectly-encoded multibyte character near the end of a stringcould cause various processing loops to run past the string'sterminating NUL, with results ranging from no detectable issue toa program crash, depending on what happens to be in the followingmemory.This isn't an issue in the server, because we take care to verifythe encoding of strings before doing any interesting processingon them. However, that lack of care leaked into client-side codewhich shouldn't assume that anyone has validated the encoding ofits input.Although this is certainly a bug worth fixing, the PG security teamelected not to regard it as a security issue, primarily becauseany untrusted text should be sanitized by PQescapeLiteral orthe like before being incorporated into a SQL or psql command.(If an app fails to do so, the same technique can be used tocause SQL injection, with probably much more dire consequencesthan a mere client-program crash.) Those functions were alreadymade proof against this class of problem, cfCVE-2006-2313.To fix, invent PQmblenBounded() which is like PQmblen() except itwon't return more than the number of bytes remaining in the string.In HEAD we can make this a new libpq function, as PQmblen() is.It seems imprudent to change libpq's API in stable branches though,so in the back branches define PQmblenBounded as a macro in the filesthat need it. (Note that just changing PQmblen's behavior would notbe a good idea; notably, it would completely break the escapingfunctions' defense against this exact problem. So we just want aversion for those callers that don't have any better way of handlingthis issue.)Per private report from houjingyi. Back-patch to all supported branches.1 parent68a6d8a commit42f94f5
File tree
15 files changed
+68
-33
lines changed- src
- bin
- psql
- scripts
- common
- fe_utils
- include/mb
- interfaces/libpq
15 files changed
+68
-33
lines changedLines changed: 13 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1846 | 1846 |
| |
1847 | 1847 |
| |
1848 | 1848 |
| |
1849 |
| - | |
| 1849 | + | |
1850 | 1850 |
| |
1851 | 1851 |
| |
1852 | 1852 |
| |
| |||
1883 | 1883 |
| |
1884 | 1884 |
| |
1885 | 1885 |
| |
1886 |
| - | |
| 1886 | + | |
1887 | 1887 |
| |
1888 | 1888 |
| |
1889 | 1889 |
| |
| |||
1918 | 1918 |
| |
1919 | 1919 |
| |
1920 | 1920 |
| |
1921 |
| - | |
| 1921 | + | |
1922 | 1922 |
| |
1923 | 1923 |
| |
1924 | 1924 |
| |
| |||
1949 | 1949 |
| |
1950 | 1950 |
| |
1951 | 1951 |
| |
1952 |
| - | |
| 1952 | + | |
1953 | 1953 |
| |
1954 | 1954 |
| |
1955 | 1955 |
| |
| |||
1983 | 1983 |
| |
1984 | 1984 |
| |
1985 | 1985 |
| |
1986 |
| - | |
| 1986 | + | |
1987 | 1987 |
| |
1988 | 1988 |
| |
1989 | 1989 |
| |
| |||
1999 | 1999 |
| |
2000 | 2000 |
| |
2001 | 2001 |
| |
2002 |
| - | |
| 2002 | + | |
2003 | 2003 |
| |
2004 | 2004 |
| |
2005 | 2005 |
| |
| |||
2010 | 2010 |
| |
2011 | 2011 |
| |
2012 | 2012 |
| |
2013 |
| - | |
| 2013 | + | |
2014 | 2014 |
| |
2015 | 2015 |
| |
2016 | 2016 |
| |
| |||
2027 | 2027 |
| |
2028 | 2028 |
| |
2029 | 2029 |
| |
2030 |
| - | |
| 2030 | + | |
2031 | 2031 |
| |
2032 | 2032 |
| |
2033 | 2033 |
| |
| |||
2050 | 2050 |
| |
2051 | 2051 |
| |
2052 | 2052 |
| |
2053 |
| - | |
| 2053 | + | |
2054 | 2054 |
| |
2055 | 2055 |
| |
2056 | 2056 |
| |
| |||
2065 | 2065 |
| |
2066 | 2066 |
| |
2067 | 2067 |
| |
2068 |
| - | |
| 2068 | + | |
2069 | 2069 |
| |
2070 | 2070 |
| |
2071 | 2071 |
| |
| |||
2084 | 2084 |
| |
2085 | 2085 |
| |
2086 | 2086 |
| |
2087 |
| - | |
| 2087 | + | |
2088 | 2088 |
| |
2089 | 2089 |
| |
2090 | 2090 |
| |
| |||
2104 | 2104 |
| |
2105 | 2105 |
| |
2106 | 2106 |
| |
2107 |
| - | |
| 2107 | + | |
2108 | 2108 |
| |
2109 | 2109 |
| |
2110 | 2110 |
| |
| |||
2140 | 2140 |
| |
2141 | 2141 |
| |
2142 | 2142 |
| |
2143 |
| - | |
| 2143 | + | |
2144 | 2144 |
| |
2145 | 2145 |
| |
2146 | 2146 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
753 | 753 |
| |
754 | 754 |
| |
755 | 755 |
| |
756 |
| - | |
| 756 | + | |
757 | 757 |
| |
758 | 758 |
| |
759 | 759 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
143 | 143 |
| |
144 | 144 |
| |
145 | 145 |
| |
146 |
| - | |
| 146 | + | |
147 | 147 |
| |
148 | 148 |
| |
149 | 149 |
| |
| |||
262 | 262 |
| |
263 | 263 |
| |
264 | 264 |
| |
265 |
| - | |
| 265 | + | |
266 | 266 |
| |
267 | 267 |
| |
268 | 268 |
| |
| |||
324 | 324 |
| |
325 | 325 |
| |
326 | 326 |
| |
327 |
| - | |
| 327 | + | |
328 | 328 |
| |
329 | 329 |
| |
330 | 330 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4397 | 4397 |
| |
4398 | 4398 |
| |
4399 | 4399 |
| |
4400 |
| - | |
| 4400 | + | |
4401 | 4401 |
| |
4402 | 4402 |
| |
4403 | 4403 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
52 | 52 |
| |
53 | 53 |
| |
54 | 54 |
| |
55 |
| - | |
| 55 | + | |
56 | 56 |
| |
57 | 57 |
| |
58 | 58 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
740 | 740 |
| |
741 | 741 |
| |
742 | 742 |
| |
743 |
| - | |
| 743 | + | |
744 | 744 |
| |
745 | 745 |
| |
746 | 746 |
| |
| |||
846 | 846 |
| |
847 | 847 |
| |
848 | 848 |
| |
849 |
| - | |
| 849 | + | |
850 | 850 |
| |
851 | 851 |
| |
852 | 852 |
| |
| |||
860 | 860 |
| |
861 | 861 |
| |
862 | 862 |
| |
863 |
| - | |
| 863 | + | |
864 | 864 |
| |
865 | 865 |
| |
866 | 866 |
| |
|
Lines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1911 | 1911 |
| |
1912 | 1912 |
| |
1913 | 1913 |
| |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
1914 | 1919 |
| |
1915 | 1920 |
| |
1916 | 1921 |
| |
| |||
1920 | 1925 |
| |
1921 | 1926 |
| |
1922 | 1927 |
| |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
1923 | 1938 |
| |
1924 | 1939 |
| |
1925 | 1940 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3636 | 3636 |
| |
3637 | 3637 |
| |
3638 | 3638 |
| |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
3639 | 3642 |
| |
3640 | 3643 |
| |
3641 | 3644 |
| |
|
Lines changed: 3 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1072 | 1072 |
| |
1073 | 1073 |
| |
1074 | 1074 |
| |
1075 |
| - | |
1076 |
| - | |
1077 |
| - | |
1078 |
| - | |
1079 |
| - | |
1080 |
| - | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
1081 | 1078 |
| |
1082 | 1079 |
| |
1083 | 1080 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
574 | 574 |
| |
575 | 575 |
| |
576 | 576 |
| |
| 577 | + | |
577 | 578 |
| |
578 | 579 |
| |
579 | 580 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
184 | 184 |
| |
185 | 185 |
| |
186 | 186 |
| |
| 187 | + |
Lines changed: 17 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1180 | 1180 |
| |
1181 | 1181 |
| |
1182 | 1182 |
| |
1183 |
| - | |
| 1183 | + | |
1184 | 1184 |
| |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
1185 | 1190 |
| |
1186 | 1191 |
| |
1187 | 1192 |
| |
| |||
1190 | 1195 |
| |
1191 | 1196 |
| |
1192 | 1197 |
| |
1193 |
| - | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
1194 | 1209 |
| |
1195 | 1210 |
| |
1196 | 1211 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
365 | 365 |
| |
366 | 366 |
| |
367 | 367 |
| |
368 |
| - | |
| 368 | + | |
369 | 369 |
| |
370 | 370 |
| |
371 | 371 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1296 | 1296 |
| |
1297 | 1297 |
| |
1298 | 1298 |
| |
1299 |
| - | |
| 1299 | + | |
1300 | 1300 |
| |
1301 | 1301 |
| |
1302 | 1302 |
| |
| |||
1364 | 1364 |
| |
1365 | 1365 |
| |
1366 | 1366 |
| |
1367 |
| - | |
| 1367 | + | |
1368 | 1368 |
| |
1369 | 1369 |
| |
1370 | 1370 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
625 | 625 |
| |
626 | 626 |
| |
627 | 627 |
| |
| 628 | + | |
| 629 | + | |
| 630 | + | |
628 | 631 |
| |
629 | 632 |
| |
630 | 633 |
| |
|
0 commit comments
Comments
(0)