Skip to content

Commit 5291995

Browse files
themironRMerl
authored andcommitted
httpd: rewrite check_xss_blacklist() to resolve buffer overrun vulnerability, and make it generally cleaner
1 parent bb24181 commit 5291995

File tree

1 file changed

+15
-47
lines changed
  • release/src/router/httpd

1 file changed

+15
-47
lines changed

release/src/router/httpd/web.c

+15-47
Original file line numberDiff line numberDiff line change
@@ -15781,66 +15781,34 @@ int is_wlif_up(const char *ifname)
1578115781

1578215782
int check_xss_blacklist(char* para, int check_www)
1578315783
{
15784-
int i = 0;
15785-
int file_len;
15786-
char *query, *para_t;
15787-
char para_str[256];
15788-
char filename[128];
15789-
char url_str[128];
15790-
memset(filename, 0, sizeof(filename));
15791-
memset(para_str, 0, sizeof(para_str));
15792-
15793-
15794-
if(para == NULL || !strcmp(para, "")){
15795-
//_dprintf("check_xss_blacklist: para is NULL\n");
15784+
char *ptr, filename[256];
15785+
if (para == NULL || *para == '\0') {
15786+
//_dprintf("check_xss_blacklist: para is NULL\n");
1579615787
return 1;
1579715788
}
1579815789

15799-
para_t = strdup(para);
15800-
while(*para) {
15801-
//if(*para=='<' || *para=='>' || *para=='%' || *para=='/' || *para=='(' || *para==')' || *para=='&') {
15802-
if(*para=='<' || *para=='>' || *para=='%' || *para=='(' || *para==')' || *para=='&') {
15803-
//_dprintf("check_xss_blacklist: para is Invalid\n");
15804-
free(para_t);
15805-
return 1;
15806-
}
15807-
else {
15808-
para_str[i] = tolower(*para);
15809-
i++;
15810-
para++;
15811-
}
15790+
// if (strpbrk(para, "<>%/()&") != NULL) {
15791+
if (strpbrk(para, "<>%()&") != NULL) {
15792+
//_dprintf("check_xss_blacklist: para is Invalid\n");
15793+
return 1;
1581215794
}
1581315795

15814-
if(strstr(para_str, "script") || strstr(para_str, "//") ){
15796+
if (strcasestr(para, "script") != NULL || strstr(para, "//") != NULL) {
1581515797
//_dprintf("check_xss_blacklist: para include script\n");
15816-
free(para_t);
1581715798
return 1;
1581815799
}
1581915800

15820-
if(check_www == 1){
15821-
memset(url_str, 0, sizeof(url_str));
15822-
if ((query = index(para_t, '?')) != NULL) {
15823-
file_len = strlen(para_t)-strlen(query);
15824-
15825-
if(file_len > sizeof(url_str))
15826-
file_len = sizeof(url_str);
15827-
15828-
strncpy(url_str, para_t, file_len);
15829-
}
15830-
else
15831-
{
15832-
strncpy(url_str, para_t, sizeof(url_str)-1);
15833-
}
15834-
15835-
snprintf(filename, sizeof(filename), "/www/%s", url_str);
15836-
if(!check_if_file_exist(filename)){
15837-
_dprintf("check_xss_blacklist:%s is not in www\n", url_str);
15838-
free(para_t);
15801+
if (check_www) {
15802+
snprintf(filename, sizeof(filename), "/www/%s", para);
15803+
ptr = strpbrk(filename, "#?");
15804+
if (ptr)
15805+
*ptr = '\0';
15806+
if (!check_if_file_exist(filename)) {
15807+
_dprintf("check_xss_blacklist: %s is not in www\n", filename);
1583915808
return 1;
1584015809
}
1584115810
}
1584215811

15843-
free(para_t);
1584415812
return 0;
1584515813
}
1584615814

0 commit comments

Comments
 (0)