Skip to content

Commit a160108

Browse files
committed
httpd: fix buffer overrun in ej_update_variables() (fixes CVE-2018-5721)
1 parent e38bab2 commit a160108

File tree

1 file changed

+5
-7
lines changed
  • release/src/router/httpd

1 file changed

+5
-7
lines changed

release/src/router/httpd/web.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -3234,18 +3234,16 @@ static int ej_update_variables(int eid, webs_t wp, int argc, char_t **argv) {
32343234
#endif
32353235

32363236
if (strlen(action_script) > 0) {
3237-
char *p1, *p2;
3237+
char *p1, p2[sizeof(notify_cmd)];
32383238

3239-
memset(notify_cmd, 0, sizeof(notify_cmd));
32403239
if((p1 = strstr(action_script, "_wan_if")))
32413240
{
3242-
p1 += 7;
3243-
strncpy(notify_cmd, action_script, p1 - action_script);
3244-
p2 = notify_cmd + strlen(notify_cmd);
3245-
sprintf(p2, " %s%s", wan_unit, p1);
3241+
p1 += sizeof("_wan_if") - 1;
3242+
strlcpy(p2, action_script, MIN(p1 - action_script + 1, sizeof(p2)));
3243+
snprintf(notify_cmd, sizeof(notify_cmd), "%s %s%s", p2, wan_unit, p1);
32463244
}
32473245
else
3248-
strncpy(notify_cmd, action_script, 128);
3246+
strlcpy(notify_cmd, action_script, sizeof(notify_cmd));
32493247

32503248
if(strcmp(action_script, "saveNvram"))
32513249
{

0 commit comments

Comments
 (0)