You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.7 KiB

  1. From 90951497008967f10ba8f9927b53c6e6bc138540 Mon Sep 17 00:00:00 2001
  2. From: Emeric Brun <ebrun@haproxy.comw>
  3. Date: Wed, 12 Nov 2014 17:35:37 +0100
  4. Subject: [PATCH 2/6] BUG/MEDIUM: ssl: fix bad ssl context init can cause
  5. segfault in case of OOM.
  6. Some SSL context's init functions errors were not handled and
  7. can cause a segfault due to an incomplete SSL context
  8. initialization.
  9. This fix must be backported to 1.5.
  10. (cherry picked from commit 5547615cdac377797ae351a2e024376dbf6d6963)
  11. ---
  12. src/ssl_sock.c | 44 ++++++++++++++++++++++++++++++++++----------
  13. 1 file changed, 34 insertions(+), 10 deletions(-)
  14. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  15. index f8bfbe7..620609f 100644
  16. --- a/src/ssl_sock.c
  17. +++ b/src/ssl_sock.c
  18. @@ -2040,15 +2040,29 @@ static int ssl_sock_init(struct connection *conn)
  19. return -1;
  20. }
  21. - SSL_set_connect_state(conn->xprt_ctx);
  22. - if (objt_server(conn->target)->ssl_ctx.reused_sess)
  23. - SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess);
  24. -
  25. /* set fd on SSL session context */
  26. - SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
  27. + if (!SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd)) {
  28. + SSL_free(conn->xprt_ctx);
  29. + conn->xprt_ctx = NULL;
  30. + conn->err_code = CO_ER_SSL_NO_MEM;
  31. + return -1;
  32. + }
  33. /* set connection pointer */
  34. - SSL_set_app_data(conn->xprt_ctx, conn);
  35. + if (!SSL_set_app_data(conn->xprt_ctx, conn)) {
  36. + SSL_free(conn->xprt_ctx);
  37. + conn->xprt_ctx = NULL;
  38. + conn->err_code = CO_ER_SSL_NO_MEM;
  39. + return -1;
  40. + }
  41. +
  42. + SSL_set_connect_state(conn->xprt_ctx);
  43. + if (objt_server(conn->target)->ssl_ctx.reused_sess) {
  44. + if(!SSL_set_session(conn->xprt_ctx, objt_server(conn->target)->ssl_ctx.reused_sess)) {
  45. + SSL_SESSION_free(objt_server(conn->target)->ssl_ctx.reused_sess);
  46. + objt_server(conn->target)->ssl_ctx.reused_sess = NULL;
  47. + }
  48. + }
  49. /* leave init state and start handshake */
  50. conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;
  51. @@ -2065,13 +2079,23 @@ static int ssl_sock_init(struct connection *conn)
  52. return -1;
  53. }
  54. - SSL_set_accept_state(conn->xprt_ctx);
  55. -
  56. /* set fd on SSL session context */
  57. - SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd);
  58. + if (!SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd)) {
  59. + SSL_free(conn->xprt_ctx);
  60. + conn->xprt_ctx = NULL;
  61. + conn->err_code = CO_ER_SSL_NO_MEM;
  62. + return -1;
  63. + }
  64. /* set connection pointer */
  65. - SSL_set_app_data(conn->xprt_ctx, conn);
  66. + if (!SSL_set_app_data(conn->xprt_ctx, conn)) {
  67. + SSL_free(conn->xprt_ctx);
  68. + conn->xprt_ctx = NULL;
  69. + conn->err_code = CO_ER_SSL_NO_MEM;
  70. + return -1;
  71. + }
  72. +
  73. + SSL_set_accept_state(conn->xprt_ctx);
  74. /* leave init state and start handshake */
  75. conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN;
  76. --
  77. 2.0.4