forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9626325
committed
Add heuristic incoming-message-size limits in the server.
We had a report of confusing server behavior caused by a client bugthat sent junk to the server: the server thought the junk was avery long message length and waited patiently for data that wouldnever come. We can reduce the risk of that by being less trustingabout message lengths.For a long time, libpq has had a heuristic rule that it wouldn'tbelieve large message size words, except for a small number ofmessage types that are expected to be (potentially) long. Thisprovides some defense against loss of message-boundary sync andother corrupted-data cases. The server does something similar,except that up to now it only limited the lengths of messagesreceived during the connection authentication phase. Let'sdo the same as in libpq and put restrictions on the allowedlength of all messages, while distinguishing between messagetypes that are expected to be long and those that aren't.I used a limit of 10000 bytes for non-long messages. (libpq'scorresponding limit is 30000 bytes, but given the asymmetry ofthe FE/BE protocol, there's no good reason why the numbers shouldbe the same.) Experimentation suggests that this is at least afactor of 10, maybe a factor of 100, more than we really need;but plenty of daylight seems desirable to avoid false positives.In any case we can adjust the limit based on beta-test results.For long messages, set a limit of MaxAllocSize - 1, which is themost that we can absorb into the StringInfo buffer that the messageis collected in. This just serves to make sure that a bogus messagesize is reported as such, rather than as a confusing gripe aboutnot being able to enlarge a string buffer.While at it, make sure that non-mainline code paths (such asCOPY FROM STDIN) are as paranoid as SocketBackend is, and validatethe message type code before believing the message length.This provides an additional guard against getting stuck on corruptedinput.Discussion:https://postgr.es/m/2003757.1619373089@sss.pgh.pa.us1 parentd6b8d29 commit9626325
File tree
6 files changed
+82
-19
lines changed- src
- backend
- commands
- libpq
- replication
- tcop
- include/libpq
6 files changed
+82
-19
lines changedLines changed: 25 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
265 | 265 |
| |
266 | 266 |
| |
267 | 267 |
| |
| 268 | + | |
268 | 269 |
| |
269 | 270 |
| |
270 | 271 |
| |
| |||
274 | 275 |
| |
275 | 276 |
| |
276 | 277 |
| |
277 |
| - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
278 | 300 |
| |
279 | 301 |
| |
280 | 302 |
| |
281 | 303 |
| |
| 304 | + | |
282 | 305 |
| |
283 | 306 |
| |
284 | 307 |
| |
| |||
304 | 327 |
| |
305 | 328 |
| |
306 | 329 |
| |
307 |
| - | |
308 |
| - | |
309 |
| - | |
310 |
| - | |
311 |
| - | |
| 330 | + | |
312 | 331 |
| |
313 | 332 |
| |
314 | 333 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
210 | 210 |
| |
211 | 211 |
| |
212 | 212 |
| |
| 213 | + | |
213 | 214 |
| |
214 | 215 |
| |
215 | 216 |
| |
| |||
724 | 725 |
| |
725 | 726 |
| |
726 | 727 |
| |
727 |
| - | |
| 728 | + | |
728 | 729 |
| |
729 | 730 |
| |
730 | 731 |
| |
|
Lines changed: 2 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1203 | 1203 |
| |
1204 | 1204 |
| |
1205 | 1205 |
| |
1206 |
| - | |
| 1206 | + | |
1207 | 1207 |
| |
1208 | 1208 |
| |
1209 | 1209 |
| |
| |||
1230 | 1230 |
| |
1231 | 1231 |
| |
1232 | 1232 |
| |
1233 |
| - | |
1234 |
| - | |
| 1233 | + | |
1235 | 1234 |
| |
1236 | 1235 |
| |
1237 | 1236 |
| |
|
Lines changed: 23 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1704 | 1704 |
| |
1705 | 1705 |
| |
1706 | 1706 |
| |
| 1707 | + | |
1707 | 1708 |
| |
1708 | 1709 |
| |
1709 | 1710 |
| |
| |||
1733 | 1734 |
| |
1734 | 1735 |
| |
1735 | 1736 |
| |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
1736 | 1756 |
| |
1737 | 1757 |
| |
1738 |
| - | |
| 1758 | + | |
1739 | 1759 |
| |
1740 | 1760 |
| |
1741 | 1761 |
| |
1742 | 1762 |
| |
1743 | 1763 |
| |
1744 | 1764 |
| |
1745 | 1765 |
| |
1746 |
| - | |
| 1766 | + | |
1747 | 1767 |
| |
1748 | 1768 |
| |
1749 | 1769 |
| |
| |||
1776 | 1796 |
| |
1777 | 1797 |
| |
1778 | 1798 |
| |
1779 |
| - | |
1780 |
| - | |
1781 |
| - | |
1782 |
| - | |
| 1799 | + | |
1783 | 1800 |
| |
1784 | 1801 |
| |
1785 | 1802 |
| |
|
Lines changed: 21 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
343 | 343 |
| |
344 | 344 |
| |
345 | 345 |
| |
| 346 | + | |
346 | 347 |
| |
347 | 348 |
| |
348 | 349 |
| |
| |||
375 | 376 |
| |
376 | 377 |
| |
377 | 378 |
| |
378 |
| - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
379 | 382 |
| |
380 | 383 |
| |
381 | 384 |
| |
382 | 385 |
| |
383 | 386 |
| |
384 | 387 |
| |
385 | 388 |
| |
| 389 | + | |
386 | 390 |
| |
387 | 391 |
| |
388 | 392 |
| |
389 | 393 |
| |
| 394 | + | |
390 | 395 |
| |
391 | 396 |
| |
392 | 397 |
| |
393 | 398 |
| |
| 399 | + | |
394 | 400 |
| |
395 | 401 |
| |
396 | 402 |
| |
397 | 403 |
| |
398 | 404 |
| |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
399 | 410 |
| |
400 | 411 |
| |
401 | 412 |
| |
402 | 413 |
| |
403 |
| - | |
| 414 | + | |
404 | 415 |
| |
405 | 416 |
| |
406 | 417 |
| |
407 | 418 |
| |
| 419 | + | |
408 | 420 |
| |
409 | 421 |
| |
410 | 422 |
| |
411 | 423 |
| |
412 | 424 |
| |
413 | 425 |
| |
414 | 426 |
| |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
415 | 431 |
| |
416 | 432 |
| |
| 433 | + | |
417 | 434 |
| |
418 | 435 |
| |
419 | 436 |
| |
| |||
427 | 444 |
| |
428 | 445 |
| |
429 | 446 |
| |
| 447 | + | |
430 | 448 |
| |
431 | 449 |
| |
432 | 450 |
| |
| |||
435 | 453 |
| |
436 | 454 |
| |
437 | 455 |
| |
438 |
| - | |
| 456 | + | |
439 | 457 |
| |
440 | 458 |
| |
441 | 459 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
21 | 21 |
| |
22 | 22 |
| |
23 | 23 |
| |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
24 | 33 |
| |
25 | 34 |
| |
26 | 35 |
| |
|
0 commit comments
Comments
(0)