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.

48 lines
1.6 KiB

  1. commit a1110e24e5be53ba5fe9ab82372c02a60da06cf9
  2. Author: Emeric Brun <ebrun@haproxy.com>
  3. Date: Tue Jul 17 09:47:07 2018 -0400
  4. BUG/MINOR: map: fix map_regm with backref
  5. Due to a cascade of get_trash_chunk calls the sample is
  6. corrupted when we want to read it.
  7. The fix consist to use a temporary chunk to copy the sample
  8. value and use it.
  9. (cherry picked from commit 271022150d7961b9aa39dbfd88e0c6a4bc48c3ee)
  10. Signed-off-by: Willy Tarreau <w@1wt.eu>
  11. diff --git a/src/map.c b/src/map.c
  12. index a9a1e53c..da399088 100644
  13. --- a/src/map.c
  14. +++ b/src/map.c
  15. @@ -184,10 +184,27 @@ static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *pr
  16. if (pat->data) {
  17. /* In the regm case, merge the sample with the input. */
  18. if ((long)private == PAT_MATCH_REGM) {
  19. + struct chunk *tmptrash;
  20. +
  21. + /* Copy the content of the sample because it could
  22. + be scratched by incoming get_trash_chunk */
  23. + tmptrash = alloc_trash_chunk();
  24. + if (!tmptrash)
  25. + return 0;
  26. +
  27. + tmptrash->len = smp->data.u.str.len;
  28. + if (tmptrash->len > (tmptrash->size-1))
  29. + tmptrash->len = tmptrash->size-1;
  30. +
  31. + memcpy(tmptrash->str, smp->data.u.str.str, tmptrash->len);
  32. + tmptrash->str[tmptrash->len] = 0;
  33. +
  34. str = get_trash_chunk();
  35. - str->len = exp_replace(str->str, str->size, smp->data.u.str.str,
  36. + str->len = exp_replace(str->str, str->size, tmptrash->str,
  37. pat->data->u.str.str,
  38. (regmatch_t *)smp->ctx.a[0]);
  39. +
  40. + free_trash_chunk(tmptrash);
  41. if (str->len == -1)
  42. return 0;
  43. smp->data.u.str = *str;