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.

49 lines
2.1 KiB

  1. From 3f34b5539e7ba31e44055d853b9ba496e73e0bae Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Mon, 7 Sep 2015 19:32:33 +0200
  4. Subject: [PATCH 15/16] BUG/MAJOR: http: don't call http_send_name_header()
  5. after an error
  6. A crash was reported when using the "famous" http-send-name-header
  7. directive. This time it's a bit tricky, it requires a certain number of
  8. conditions to be met including maxconn on a server, queuing, timeout in
  9. the queue and cookie-based persistence.
  10. The problem is that in stream.c, before calling http_send_name_header(),
  11. we check a number of conditions to know if we have to replace the header
  12. name. But prior to reaching this place, it's possible for
  13. sess_update_stream_int() to fail and change the stream-int's state to
  14. SI_ST_CLO, send an error 503 to the client, and flush all buffers. But
  15. http_send_name_header() can only be called with valid buffer contents
  16. matching the http_msg's description. So when it rewinds the stream to
  17. modify the header, buf->o becomes negative by the size of the incoming
  18. request and is used as the argument to memmove() which basically
  19. displaces 4GB of memory off a few bytes to write the new name, resulting
  20. in a core and a core file that's really not fun to play with.
  21. The solution obviously consists in refraining from calling this nasty
  22. function when the stream interface is already closed.
  23. This bug also affects 1.5 and possibly 1.4, so the fix must be backported
  24. there.
  25. (cherry picked from commit 9c03b33329cb4924716edc1c851913a18b0670dc)
  26. ---
  27. src/session.c | 2 +-
  28. 1 file changed, 1 insertion(+), 1 deletion(-)
  29. diff --git a/src/session.c b/src/session.c
  30. index 6d62e36..7520a85 100644
  31. --- a/src/session.c
  32. +++ b/src/session.c
  33. @@ -2293,7 +2293,7 @@ struct task *process_session(struct task *t)
  34. /* Now we can add the server name to a header (if requested) */
  35. /* check for HTTP mode and proxy server_name_hdr_name != NULL */
  36. - if ((s->si[1].state >= SI_ST_CON) &&
  37. + if ((s->si[1].state >= SI_ST_CON) && (s->si[1].state < SI_ST_CLO) &&
  38. (s->be->server_id_hdr_name != NULL) &&
  39. (s->be->mode == PR_MODE_HTTP) &&
  40. objt_server(s->target)) {
  41. --
  42. 2.4.6