Module: sip-router
Branch: 3.3
Commit: 8e98fd0a708f96c98b942b1fcfa77a5b6e45496d
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8e98fd0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed May 15 22:45:18 2013 +0200
pv: clone result of several string transformations
- it is safer for assigning back to the same variable on which the
transformation was applied
- reported by Martin Mikkelsen
(cherry picked from commit fe7e4a5152674aa9c81c09dd2fc9938d9e9e762e)
Conflicts:
modules_k/pv/pv_trans.c
---
modules_k/pv/pv_trans.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/modules_k/pv/pv_trans.c b/modules_k/pv/pv_trans.c
index af455eb..76efe1c 100644
--- a/modules_k/pv/pv_trans.c
+++ b/modules_k/pv/pv_trans.c
@@ -94,6 +94,15 @@ char *tr_set_crt_buffer(void)
return _tr_buffer;
}
+#define tr_string_clone_result do { \
+ if(val->rs.len>TR_BUFFER_SIZE-1) { \
+ LM_ERR("result is too big\n"); \
+ return -1; \
+ } \
+ strncpy(_tr_buffer, val->rs.s, val->rs.len); \
+ val->rs.s = _tr_buffer; \
+ } while(0);
+
/*!
* \brief Evaluate string transformations
* \param msg SIP message
@@ -323,6 +332,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
{ /* to end */
val->rs.s += i;
val->rs.len -= i;
+ tr_string_clone_result;
break;
}
val->rs.s += i;
@@ -340,10 +350,12 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int
subtype,
{ /* to end */
val->rs.s += val->rs.len-i;
val->rs.len = i;
+ tr_string_clone_result;
break;
}
val->rs.s += val->rs.len-i;
val->rs.len = j;
+ tr_string_clone_result;
break;
case TR_S_SELECT:
@@ -414,6 +426,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
val->rs = _tr_empty;
}
}
+ tr_string_clone_result;
break;
case TR_S_TOLOWER:
@@ -489,6 +502,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
if(subtype==TR_S_STRIP)
val->rs.s += i;
val->rs.len -= i;
+ tr_string_clone_result;
break;
case TR_S_PREFIXES: