Skip to content

Commit

Permalink
pv: use unsigned for safer non-ascii bit shifting for hexa
Browse files Browse the repository at this point in the history
- related to GH #2690
  • Loading branch information
miconda committed Mar 28, 2021
1 parent 9efe1e0 commit c331e6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/modules/pv/pv_core.c
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/modules/pv/pv_trans.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit c331e6d

Please sign in to comment.