SHARE
TWEET

Untitled

a guest Oct 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/transformations.c b/transformations.c
  2. index c1ad7c967..f5c63b4c5 100644
  3. --- a/transformations.c
  4. +++ b/transformations.c
  5. @@ -53,7 +53,16 @@
  6.  
  7.  #define TR_BUFFER_SIZE 65536
  8.  
  9. -static char _tr_buffer[TR_BUFFER_SIZE];
  10. +/* two buffers are enough to allow infinite chaining (R/W <-> W/R) */
  11. +#define TR_INF_CHAINS  2
  12. +
  13. +/* a separate set of chaining buffers for each script function argument */
  14. +static char __tr_buffers[MAX_ACTION_ELEMS - 1][TR_INF_CHAINS][TR_BUFFER_SIZE];
  15. +static int __crt_tr_buf, __crt_tr_link;
  16. +
  17. +#define get_tr_buffer() \
  18. +   __tr_buffers[__crt_tr_buf] \
  19. +       [__crt_tr_link = (__crt_tr_link + 1) % TR_INF_CHAINS]
  20.  
  21.  trans_extra_t *tr_extra_list;
  22.  
  23. @@ -144,21 +153,27 @@ int run_transformations(struct sip_msg *msg, trans_t *tr, pv_value_t *val)
  24.  
  25.     if (tr==NULL || val==NULL) {
  26.         LM_DBG("null pointer\n");
  27. -       return -1;
  28. +       ret = -1;
  29. +       goto out;
  30.     }
  31.  
  32.     it = tr;
  33.     while (it) {
  34.         ret = (*it->trf)(msg, it->params, it->subtype, val);
  35.         if(ret!=0)
  36. -           return ret;
  37. +           goto out;
  38.         it = it->next;
  39.     }
  40.  
  41. -   return 0;
  42. +out:
  43. +   /* advancing the current set of buffers prevents any bugs when passing
  44. +    * multiple transformation-enabled vars as cfg function parameters */
  45. +   __crt_tr_buf = (__crt_tr_buf + 1) % (MAX_ACTION_ELEMS - 1);
  46. +
  47. +   return ret;
  48.  }
  49.  
  50. -static void trans_fill_left(pv_value_t *val, str pad, int len)
  51. +static void trans_fill_left(pv_value_t *val, str pad, int len, char *_tr_buffer)
  52.  {
  53.     char *p;
  54.     int r;
  55. @@ -201,7 +216,7 @@ static void trans_fill_left(pv_value_t *val, str pad, int len)
  56.     }
  57.  }
  58.  
  59. -static void trans_fill_right(pv_value_t *val, str pad, int len)
  60. +static void trans_fill_right(pv_value_t *val, str pad, int len, char *_tr_buffer)
  61.  {
  62.     char *p;
  63.     int r;
  64. @@ -237,7 +252,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
  65.         pv_value_t *val)
  66.  {
  67.     int i, j;
  68. -   char *p, *s;
  69. +   char *p, *s, *_tr_buffer = get_tr_buffer();
  70.     str st;
  71.     pv_value_t v;
  72.  
  73. @@ -776,9 +791,9 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
  74.                 return 0;
  75.  
  76.             if (subtype == TR_S_FILL_LEFT)
  77. -               trans_fill_left(val, st, i);
  78. +               trans_fill_left(val, st, i, _tr_buffer);
  79.             else
  80. -               trans_fill_right(val, st, i);
  81. +               trans_fill_right(val, st, i, _tr_buffer);
  82.  
  83.             break;
  84.         case TR_S_WIDTH:
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top