From c331e6dddb238abe5fc832ce3d3934fbe56ad2f7 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sat, 27 Mar 2021 14:43:05 +0100 Subject: [PATCH] pv: use unsigned for safer non-ascii bit shifting for hexa - related to GH #2690 --- src/modules/pv/pv_core.c | 10 ++++++---- src/modules/pv/pv_trans.c | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c index 5137048e105..103f9dd5ec1 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<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 cbee7d6caa5..e8d287bfe02 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; irs.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';