diff --git a/httpd/httpd.c b/httpd/httpd.c index ab61ca7c..dfd0db21 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -532,6 +532,19 @@ uint8_t stream_upload(void) crc16_bank1(upload_settings.p + upload_settings.bptr); flash_buf[write_len++] = upload_settings.p[upload_settings.bptr++]; if (write_len >= FLASH_PAGE_SIZE) { + /* The staged image spans FIRMWARE_UPLOAD_START to twice that, + * the span check_and_flash_update_image() reads back. Nothing + * else bounds uptr: a body whose closing boundary never arrives + * keeps writing, and on a flash exactly this size the address + * wraps onto the running image at zero. */ + if (uptr >= (uint32_t)FIRMWARE_UPLOAD_START * 2) { + print_string("Upload runs past the image area! Aborting.\n"); + slen = strtox(outbuf, "HTTP/1.1 400 Bad Request\r\nContent-Length: 30\r\n" + "Content-Type: text/plain\r\n\r\n" + "NO: upload exceeds image area\n"); + s->tstate = TSTATE_NONE; + return 0; + } dbg_string("len: "); dbg_short(write_len); dbg_char(' '); dbg_string("CRC16: "); dbg_short(crc_value); dbg_char('\n'); if (uptr % FLASH_SECTOR_SIZE == 0) {