Module: kamailio
Branch: master
Commit: c331e6dddb238abe5fc832ce3d3934fbe56ad2f7
URL:
https://github.com/kamailio/kamailio/commit/c331e6dddb238abe5fc832ce3d3934f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-03-28T11:11:08+02:00
pv: use unsigned for safer non-ascii bit shifting for hexa
- related to GH #2690
---
Modified: src/modules/pv/pv_core.c
Modified: src/modules/pv/pv_trans.c
---
Diff:
https://github.com/kamailio/kamailio/commit/c331e6dddb238abe5fc832ce3d3934f…
Patch:
https://github.com/kamailio/kamailio/commit/c331e6dddb238abe5fc832ce3d3934f…
---
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index 5137048e10..103f9dd5ec 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -615,20 +615,22 @@ int pv_get_flag(struct sip_msg *msg, pv_param_t *param,
return pv_get_uintval(msg, param, res, (msg->flags &
(1<<param->pvn.u.isname.name.n)) ? 1 : 0);
}
-static inline char* int_to_8hex(int val)
+static inline char* int_to_8hex(int sval)
{
unsigned short digit;
int i;
static char outbuf[9];
+ unsigned int uval;
+ uval = (unsigned int)sval;
outbuf[8] = '\0';
for(i=0; i<8; i++)
{
- if(val!=0)
+ if(uval!=0)
{
- digit = val & 0x0f;
+ digit = uval & 0x0f;
outbuf[7-i] = digit >= 10 ? digit + 'a' - 10 : digit + '0';
- val >>= 4;
+ uval >>= 4;
}
else
outbuf[7-i] = '0';
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index cbee7d6caa..e8d287bfe0 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -118,7 +118,7 @@ static int pdu_7bit_encode(str sin) {
nleft = 1;
j = 0;
for(i = 0; i < sin.len; i++) {
- hex = *(sin.s) >> (nleft - 1);
+ hex = (unsigned char)(*(sin.s)) >> (nleft - 1);
fill = *(sin.s+1) << (8-nleft);
hex = hex | fill;
_tr_buffer[j++] = HexTbl[hex >> 4];
@@ -292,7 +292,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
j = 0;
for(i=0; i<val->rs.len; i++)
{
- _tr_buffer[j++] = fourbits2char[val->rs.s[i] >> 4];
+ _tr_buffer[j++] = fourbits2char[(unsigned char)val->rs.s[i] >> 4];
_tr_buffer[j++] = fourbits2char[val->rs.s[i] & 0xf];
}
_tr_buffer[j] = '\0';