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.

116 lines
4.6 KiB

  1. From 5bff05986c501d9ffb67873b60472f9c2a2e41be Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Wed, 13 May 2015 12:24:53 +0200
  4. Subject: [PATCH 8/8] BUG/MEDIUM: checks: do not dereference a list as a
  5. tcpcheck struct
  6. The method used to skip to next rule in the list is wrong, it assumes
  7. that the list element starts at the same offset as the rule. It happens
  8. to be true on most architectures since the list is the first element for
  9. now but it's definitely wrong. Now the code doesn't crash anymore when
  10. the struct list is moved anywhere else in the struct tcpcheck_rule.
  11. This fix must be backported to 1.5.
  12. (cherry picked from commit 5581c27b579cbfc53afb0ca04cdeebe7e2200131)
  13. [wt: changes from 1.6 : no tcp-check comments, check becomes s->proxy]
  14. ---
  15. src/cfgparse.c | 18 +++++++-----------
  16. src/checks.c | 15 +++++++++------
  17. 2 files changed, 16 insertions(+), 17 deletions(-)
  18. diff --git a/src/cfgparse.c b/src/cfgparse.c
  19. index dba59d1..e04eff8 100644
  20. --- a/src/cfgparse.c
  21. +++ b/src/cfgparse.c
  22. @@ -4362,20 +4362,16 @@ stats_error_parsing:
  23. const char *ptr_arg;
  24. int cur_arg;
  25. struct tcpcheck_rule *tcpcheck;
  26. - struct list *l;
  27. /* check if first rule is also a 'connect' action */
  28. - l = (struct list *)&curproxy->tcpcheck_rules;
  29. - if (l->p != l->n) {
  30. - tcpcheck = (struct tcpcheck_rule *)l->n;
  31. + tcpcheck = LIST_NEXT(&curproxy->tcpcheck_rules, struct tcpcheck_rule *, list);
  32. - if (&tcpcheck->list != &curproxy->tcpcheck_rules
  33. - && tcpcheck->action != TCPCHK_ACT_CONNECT) {
  34. - Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n",
  35. - file, linenum);
  36. - err_code |= ERR_ALERT | ERR_FATAL;
  37. - goto out;
  38. - }
  39. + if (&tcpcheck->list != &curproxy->tcpcheck_rules
  40. + && tcpcheck->action != TCPCHK_ACT_CONNECT) {
  41. + Alert("parsing [%s:%d] : first step MUST also be a 'connect' when there is a 'connect' step in the tcp-check ruleset.\n",
  42. + file, linenum);
  43. + err_code |= ERR_ALERT | ERR_FATAL;
  44. + goto out;
  45. }
  46. cur_arg = 2;
  47. diff --git a/src/checks.c b/src/checks.c
  48. index e13d561..27a23b2 100644
  49. --- a/src/checks.c
  50. +++ b/src/checks.c
  51. @@ -1444,7 +1444,10 @@ static int connect_chk(struct task *t)
  52. quickack = check->type == 0 || check->type == PR_O2_TCPCHK_CHK;
  53. if (check->type == PR_O2_TCPCHK_CHK && !LIST_ISEMPTY(&s->proxy->tcpcheck_rules)) {
  54. - struct tcpcheck_rule *r = (struct tcpcheck_rule *) s->proxy->tcpcheck_rules.n;
  55. + struct tcpcheck_rule *r;
  56. +
  57. + r = LIST_NEXT(&s->proxy->tcpcheck_rules, struct tcpcheck_rule *, list);
  58. +
  59. /* if first step is a 'connect', then tcpcheck_main must run it */
  60. if (r->action == TCPCHK_ACT_CONNECT) {
  61. tcpcheck_main(conn);
  62. @@ -1952,7 +1955,7 @@ static void tcpcheck_main(struct connection *conn)
  63. /* have 'next' point to the next rule or NULL if we're on the
  64. * last one, connect() needs this.
  65. */
  66. - next = (struct tcpcheck_rule *)check->current_step->list.n;
  67. + next = LIST_NEXT(&check->current_step->list, struct tcpcheck_rule *, list);
  68. if (&next->list == head)
  69. next = NULL;
  70. @@ -2055,7 +2058,7 @@ static void tcpcheck_main(struct connection *conn)
  71. }
  72. /* allow next rule */
  73. - check->current_step = (struct tcpcheck_rule *)check->current_step->list.n;
  74. + check->current_step = LIST_NEXT(&check->current_step->list, struct tcpcheck_rule *, list);
  75. if (&check->current_step->list == head)
  76. break;
  77. @@ -2112,7 +2115,7 @@ static void tcpcheck_main(struct connection *conn)
  78. *check->bo->p = '\0'; /* to make gdb output easier to read */
  79. /* go to next rule and try to send */
  80. - check->current_step = (struct tcpcheck_rule *)check->current_step->list.n;
  81. + check->current_step = LIST_NEXT(&check->current_step->list, struct tcpcheck_rule *, list);
  82. if (&check->current_step->list == head)
  83. break;
  84. @@ -2200,7 +2203,7 @@ static void tcpcheck_main(struct connection *conn)
  85. /* matched and was supposed to => OK, next step */
  86. else {
  87. /* allow next rule */
  88. - check->current_step = (struct tcpcheck_rule *)check->current_step->list.n;
  89. + check->current_step = LIST_NEXT(&check->current_step->list, struct tcpcheck_rule *, list);
  90. if (&check->current_step->list == head)
  91. break;
  92. @@ -2215,7 +2218,7 @@ static void tcpcheck_main(struct connection *conn)
  93. /* not matched and was not supposed to => OK, next step */
  94. if (check->current_step->inverse) {
  95. /* allow next rule */
  96. - check->current_step = (struct tcpcheck_rule *)check->current_step->list.n;
  97. + check->current_step = LIST_NEXT(&check->current_step->list, struct tcpcheck_rule *, list);
  98. if (&check->current_step->list == head)
  99. break;
  100. --
  101. 2.0.5