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.

65 lines
2.3 KiB

  1. From a4ba9dbfc688576ffb7e0a3ce43ac0b420211bf6 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Wed, 25 Jun 2014 16:56:41 +0200
  4. Subject: [PATCH 4/6] BUG/MAJOR: sample: correctly reinitialize sample fetch
  5. context before calling sample_process()
  6. We used to only clear flags when reusing the static sample before calling
  7. sample_process(), but that's not enough because there's a context in samples
  8. that can be used by some fetch functions such as auth, headers and cookies,
  9. and not reinitializing it risks that a pointer of a different type is used
  10. in the wrong context.
  11. An example configuration which triggers the case consists in mixing hdr()
  12. and http_auth_group() which both make use of contexts :
  13. http-request add-header foo2 %[hdr(host)],%[http_auth_group(foo)]
  14. The solution is simple, initialize all the sample and not just the flags.
  15. This fix must be backported into 1.5 since it was introduced in 1.5-dev19.
  16. (cherry picked from commit 6c616e0b96106dd33d183afbda31e72799e967c3)
  17. ---
  18. src/proto_http.c | 3 +++
  19. src/sample.c | 5 +++--
  20. 2 files changed, 6 insertions(+), 2 deletions(-)
  21. diff --git a/src/proto_http.c b/src/proto_http.c
  22. index d566bcc..01fe62d 100644
  23. --- a/src/proto_http.c
  24. +++ b/src/proto_http.c
  25. @@ -9748,6 +9748,9 @@ smp_prefetch_http(struct proxy *px, struct session *s, void *l7, unsigned int op
  26. return 1;
  27. }
  28. +/* Note: these functinos *do* modify the sample. Even in case of success, at
  29. + * least the type and uint value are modified.
  30. + */
  31. #define CHECK_HTTP_MESSAGE_FIRST() \
  32. do { int r = smp_prefetch_http(px, l4, l7, opt, args, smp, 1); if (r <= 0) return r; } while (0)
  33. diff --git a/src/sample.c b/src/sample.c
  34. index 9f22ef9..3a0f3fb 100644
  35. --- a/src/sample.c
  36. +++ b/src/sample.c
  37. @@ -905,7 +905,7 @@ struct sample *sample_process(struct proxy *px, struct session *l4, void *l7,
  38. if (p == NULL) {
  39. p = &temp_smp;
  40. - p->flags = 0;
  41. + memset(p, 0, sizeof(*p));
  42. }
  43. if (!expr->fetch->process(px, l4, l7, opt, expr->arg_p, p, expr->fetch->kw))
  44. @@ -1160,7 +1160,8 @@ struct sample *sample_fetch_string(struct proxy *px, struct session *l4, void *l
  45. {
  46. struct sample *smp = &temp_smp;
  47. - smp->flags = 0;
  48. + memset(smp, 0, sizeof(*smp));
  49. +
  50. if (!sample_process(px, l4, l7, opt, expr, smp)) {
  51. if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL))
  52. return smp;
  53. --
  54. 1.8.5.5