forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita3c17b2
committed
Distrust external OpenSSL clients; clear err queue
OpenSSL has an unfortunate tendency to mix per-session state errorhandling with per-thread error handling. This can cause problems whenprograms that link to libpq with OpenSSL enabled have some other use ofOpenSSL; without care, one caller of OpenSSL may cause problems for theother caller. Backend code might similarly be affected, for examplewhen a third party extension independently uses OpenSSL without takingthe appropriate precautions.To fix, don't trust other users of OpenSSL to clear the per-thread errorqueue. Instead, clear the entire per-thread queue ahead of certain I/Ooperations when it appears that there might be trouble (these I/Ooperations mostly need to call SSL_get_error() to check for success,which relies on the queue being empty). This is slightly aggressive,but it's pretty clear that the other callers have a very dubious claimto ownership of the per-thread queue. Do this is both frontend andbackend code.Finally, be more careful about clearing our own error queue, so as tonot cause these problems ourself. It's possibly that control previouslydid not always reach SSLerrmessage(), where ERR_get_error() was supposedto be called to clear the queue's earliest code. Make sureERR_get_error() is always called, so as to spare other users of OpenSSLthe possibility of similar problems caused by libpq (as opposed toproblems caused by a third party OpenSSL library like PHP's OpenSSLextension). Again, do this is both frontend and backend code.See bug #12799 andhttps://bugs.php.net/bug.php?id=68276Based on patches by Dave Vitek and Peter Eisentraut.From: Peter Geoghegan <pg@bowt.ie>1 parentab32a40 commita3c17b2
File tree
2 files changed
+102
-45
lines changed- src
- backend/libpq
- interfaces/libpq
2 files changed
+102
-45
lines changedLines changed: 49 additions & 21 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
78 | 78 |
| |
79 | 79 |
| |
80 | 80 |
| |
81 |
| - | |
| 81 | + | |
82 | 82 |
| |
83 | 83 |
| |
84 | 84 |
| |
| |||
182 | 182 |
| |
183 | 183 |
| |
184 | 184 |
| |
185 |
| - | |
| 185 | + | |
186 | 186 |
| |
187 | 187 |
| |
188 | 188 |
| |
| |||
198 | 198 |
| |
199 | 199 |
| |
200 | 200 |
| |
201 |
| - | |
| 201 | + | |
202 | 202 |
| |
203 | 203 |
| |
204 | 204 |
| |
| |||
228 | 228 |
| |
229 | 229 |
| |
230 | 230 |
| |
231 |
| - | |
| 231 | + | |
232 | 232 |
| |
233 | 233 |
| |
234 | 234 |
| |
235 | 235 |
| |
236 |
| - | |
| 236 | + | |
237 | 237 |
| |
238 | 238 |
| |
239 | 239 |
| |
| |||
262 | 262 |
| |
263 | 263 |
| |
264 | 264 |
| |
265 |
| - | |
| 265 | + | |
266 | 266 |
| |
267 | 267 |
| |
268 | 268 |
| |
| |||
293 | 293 |
| |
294 | 294 |
| |
295 | 295 |
| |
296 |
| - | |
| 296 | + | |
297 | 297 |
| |
298 | 298 |
| |
299 | 299 |
| |
| |||
330 | 330 |
| |
331 | 331 |
| |
332 | 332 |
| |
| 333 | + | |
333 | 334 |
| |
334 | 335 |
| |
335 | 336 |
| |
| |||
339 | 340 |
| |
340 | 341 |
| |
341 | 342 |
| |
342 |
| - | |
| 343 | + | |
343 | 344 |
| |
344 | 345 |
| |
345 | 346 |
| |
346 | 347 |
| |
347 | 348 |
| |
348 | 349 |
| |
349 | 350 |
| |
350 |
| - | |
| 351 | + | |
351 | 352 |
| |
352 | 353 |
| |
353 | 354 |
| |
354 | 355 |
| |
355 | 356 |
| |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
356 | 366 |
| |
357 | 367 |
| |
358 | 368 |
| |
359 | 369 |
| |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
360 | 381 |
| |
361 | 382 |
| |
362 | 383 |
| |
| |||
390 | 411 |
| |
391 | 412 |
| |
392 | 413 |
| |
393 |
| - | |
| 414 | + | |
394 | 415 |
| |
395 | 416 |
| |
396 | 417 |
| |
| |||
499 | 520 |
| |
500 | 521 |
| |
501 | 522 |
| |
| 523 | + | |
502 | 524 |
| |
503 | 525 |
| |
| 526 | + | |
504 | 527 |
| |
505 | 528 |
| |
| 529 | + | |
506 | 530 |
| |
507 | 531 |
| |
508 | 532 |
| |
| |||
529 | 553 |
| |
530 | 554 |
| |
531 | 555 |
| |
532 |
| - | |
| 556 | + | |
533 | 557 |
| |
534 | 558 |
| |
535 | 559 |
| |
| |||
556 | 580 |
| |
557 | 581 |
| |
558 | 582 |
| |
| 583 | + | |
559 | 584 |
| |
560 | 585 |
| |
| 586 | + | |
561 | 587 |
| |
562 | 588 |
| |
| 589 | + | |
563 | 590 |
| |
564 | 591 |
| |
565 | 592 |
| |
| |||
586 | 613 |
| |
587 | 614 |
| |
588 | 615 |
| |
589 |
| - | |
| 616 | + | |
590 | 617 |
| |
591 | 618 |
| |
592 | 619 |
| |
| |||
742 | 769 |
| |
743 | 770 |
| |
744 | 771 |
| |
745 |
| - | |
| 772 | + | |
| 773 | + | |
746 | 774 |
| |
747 | 775 |
| |
748 | 776 |
| |
| |||
782 | 810 |
| |
783 | 811 |
| |
784 | 812 |
| |
785 |
| - | |
| 813 | + | |
786 | 814 |
| |
787 | 815 |
| |
788 | 816 |
| |
| |||
948 | 976 |
| |
949 | 977 |
| |
950 | 978 |
| |
951 |
| - | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
952 | 982 |
| |
953 | 983 |
| |
954 | 984 |
| |
955 | 985 |
| |
956 | 986 |
| |
957 | 987 |
| |
958 |
| - | |
| 988 | + | |
959 | 989 |
| |
960 |
| - | |
961 | 990 |
| |
962 | 991 |
| |
963 | 992 |
| |
964 |
| - | |
965 |
| - | |
| 993 | + | |
966 | 994 |
| |
967 |
| - | |
| 995 | + | |
968 | 996 |
| |
969 | 997 |
| |
970 |
| - | |
| 998 | + | |
971 | 999 |
| |
972 | 1000 |
| |
973 | 1001 |
| |
|
0 commit comments
Comments
(0)