Commit b615920
committed
Fix memory leakage in ICU encoding conversion, and other code review.
Callers of icu_to_uchar() neglected to pfree the result string when done
with it. This results in catastrophic memory leaks in varstr_cmp(),
because of our prevailing assumption that btree comparison functions don't
leak memory. For safety, make all the call sites clean up leaks, though
I suspect that we could get away without it in formatting.c. I audited
callers of icu_from_uchar() as well, but found no places that seemed to
have a comparable issue.
Add function API specifications for icu_to_uchar() and icu_from_uchar();
the lack of any thought-through specification is perhaps not unrelated
to the existence of this bug in the first place. Fix icu_to_uchar()
to guarantee a nul-terminated result; although no existing caller appears
to care, the fact that it would have been nul-terminated except in
extreme corner cases seems ideally designed to bite someone on the rear
someday. Fix ucnv_fromUChars() destCapacity argument --- in the worst
case, that could perhaps have led to a non-nul-terminated result, too.
Fix icu_from_uchar() to have a more reasonable definition of the function
result --- no callers are actually paying attention, so this isn't a live
bug, but it's certainly sloppily designed. Const-ify icu_from_uchar()'s
input string for consistency.
That is not the end of what needs to be done to these functions, but
it's as much as I have the patience for right now.
Discussion: https://postgr.es/m/1955.1498181798@sss.pgh.pa.us1 parent 8be8510 commit b615920
File tree
5 files changed
+60
-11
lines changed- src
- backend
- commands
- utils/adt
- include/utils
5 files changed
+60
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
384 | 388 | | |
385 | 389 | | |
386 | 390 | | |
| |||
397 | 401 | | |
398 | 402 | | |
399 | 403 | | |
400 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
401 | 408 | | |
402 | 409 | | |
403 | 410 | | |
| |||
407 | 414 | | |
408 | 415 | | |
409 | 416 | | |
410 | | - | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
411 | 420 | | |
412 | 421 | | |
413 | | - | |
| 422 | + | |
414 | 423 | | |
415 | 424 | | |
416 | 425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1561 | 1561 | | |
1562 | 1562 | | |
1563 | 1563 | | |
| 1564 | + | |
1564 | 1565 | | |
1565 | 1566 | | |
1566 | 1567 | | |
| |||
1684 | 1685 | | |
1685 | 1686 | | |
1686 | 1687 | | |
| 1688 | + | |
1687 | 1689 | | |
1688 | 1690 | | |
1689 | 1691 | | |
| |||
1808 | 1810 | | |
1809 | 1811 | | |
1810 | 1812 | | |
| 1813 | + | |
1811 | 1814 | | |
1812 | 1815 | | |
1813 | 1816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1486 | 1486 | | |
1487 | 1487 | | |
1488 | 1488 | | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
1489 | 1501 | | |
1490 | 1502 | | |
1491 | 1503 | | |
| |||
1494 | 1506 | | |
1495 | 1507 | | |
1496 | 1508 | | |
1497 | | - | |
| 1509 | + | |
1498 | 1510 | | |
1499 | 1511 | | |
1500 | | - | |
| 1512 | + | |
| 1513 | + | |
1501 | 1514 | | |
1502 | 1515 | | |
1503 | 1516 | | |
1504 | 1517 | | |
1505 | 1518 | | |
1506 | 1519 | | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1507 | 1531 | | |
1508 | | - | |
| 1532 | + | |
1509 | 1533 | | |
1510 | 1534 | | |
1511 | 1535 | | |
| |||
1515 | 1539 | | |
1516 | 1540 | | |
1517 | 1541 | | |
1518 | | - | |
| 1542 | + | |
| 1543 | + | |
1519 | 1544 | | |
1520 | 1545 | | |
1521 | 1546 | | |
1522 | 1547 | | |
1523 | 1548 | | |
1524 | | - | |
| 1549 | + | |
1525 | 1550 | | |
1526 | 1551 | | |
1527 | 1552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1569 | 1569 | | |
1570 | 1570 | | |
1571 | 1571 | | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
1572 | 1575 | | |
1573 | 1576 | | |
1574 | 1577 | | |
| |||
2155 | 2158 | | |
2156 | 2159 | | |
2157 | 2160 | | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
2158 | 2164 | | |
2159 | 2165 | | |
2160 | 2166 | | |
| |||
2279 | 2285 | | |
2280 | 2286 | | |
2281 | 2287 | | |
2282 | | - | |
| 2288 | + | |
2283 | 2289 | | |
2284 | 2290 | | |
2285 | 2291 | | |
| |||
2354 | 2360 | | |
2355 | 2361 | | |
2356 | 2362 | | |
2357 | | - | |
| 2363 | + | |
| 2364 | + | |
2358 | 2365 | | |
2359 | 2366 | | |
2360 | 2367 | | |
| |||
2394 | 2401 | | |
2395 | 2402 | | |
2396 | 2403 | | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
2397 | 2409 | | |
2398 | 2410 | | |
2399 | 2411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
0 commit comments