Skip to content

Commit

Permalink
Fix escaping URI parameters - skip alphanumerical chars.
Browse files Browse the repository at this point in the history
Reported by Ben Newlin on "user" mailing list.

(cherry picked from commit b5094f0)
  • Loading branch information
bogdan-iancu committed Oct 17, 2017
1 parent 18a9ad1 commit bdc1d68
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions strcommon.c
Expand Up @@ -274,8 +274,7 @@ int escape_user(str *sin, str *sout)
LM_ERR("invalid escaped character <%u>\n", (unsigned int)*p);
return -1;
}
if (isdigit((int)*p) || ((*p >= 'A') && (*p <= 'Z')) ||
((*p >= 'a') && (*p <= 'z')))
if (isalnum((int)*p))
{
*at = *p;
} else {
Expand Down Expand Up @@ -358,42 +357,46 @@ int escape_param(str *sin, str *sout)
LM_ERR("invalid escaped character <%u>\n", (unsigned int)*p);
return -1;
}
switch (*p) {
/* unreserved chars */
case '-':
case '_':
case '.':
case '!':
case '~':
case '*':
case '\'':
case '(':
case ')':
/* param unreserved chars */
case '[':
case ']':
case '/':
case ':':
case '&':
case '+':
case '$':
*at = *p;
break;
default:
*at++ = '%';
x = (*p) >> 4;
if (x < 10)
{
*at++ = x + '0';
} else {
*at++ = x - 10 + 'a';
}
x = (*p) & 0x0f;
if (x < 10) {
*at = x + '0';
} else {
*at = x - 10 + 'a';
}
if (isalnum((int)*p)) {
*at = *p;
} else {
switch (*p) {
/* unreserved chars */
case '-':
case '_':
case '.':
case '!':
case '~':
case '*':
case '\'':
case '(':
case ')':
/* param unreserved chars */
case '[':
case ']':
case '/':
case ':':
case '&':
case '+':
case '$':
*at = *p;
break;
default:
*at++ = '%';
x = (*p) >> 4;
if (x < 10)
{
*at++ = x + '0';
} else {
*at++ = x - 10 + 'a';
}
x = (*p) & 0x0f;
if (x < 10) {
*at = x + '0';
} else {
*at = x - 10 + 'a';
}
}
}
at++;
p++;
Expand Down

0 comments on commit bdc1d68

Please sign in to comment.