-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The bug is one line. The patch is the same line.\n\n`fetch_jpg()` is the function the scripter calls when a user script invokes `jpg(0, \"host/stream\", x, y, scale)` to pull an MJPEG feed onto a display. Selector `0` opens the connection. The first thing it does after the GET is read back the server's `Content-Type` header to learn the multipart boundary:\n\n```cpp\n// tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino, fetch_jpg() case 0\nString boundary = glob_script_mem.jpg_task.http.header(headerKeys[0]);\nchar *cp = strchr(boundary.c_str(), '=');\nif (cp) {\n strcpy(glob_script_mem.jpg_task.boundary, cp + 1); // pre-patch\n}\n```\n\n`headerKeys[0]` is `\"Content-Type\"`. The server sends, for example, `multipart/x-mixed-replace; boundary=frame`. `strchr` finds the `=`. Everything after it goes into `glob_script_mem.jpg_task.boundary`, declared as:\n\n```cpp\nstruct JPG_TASK {\n char boundary[40];\n bool draw;\n uint8_t scale;\n uint16_t xp;\n uint16_t yp;\n WiFiClient stream;\n HTTPClient http;\n} jpg_task;\n```\n\nForty bytes for the boundary, with the live `WiFiClient` and `HTTPClient` instances seven bytes downstream after struct alignment. `strcpy` does not know any of this. It copies until it hits a NUL.\n\nThe patch, May 16 2026, commit `5009bea`:\n\n```diff\n- strcpy(glob_script_mem.jpg_task.boundary,cp + 1);\n+ strlcpy(glob_script_mem.jpg_task.boundary, cp + 1, sizeof(glob_script_mem.jpg_task.boundary));\n```\n\nOne line. The fix is correct. There is nothing more to say about the line.\n\n## The struct after the buffer is the exploit primitive\n\n`WiFiClient` and `HTTPClient` are Arduino classes; their instances carry vtable pointers as their first machine word. The vtable pointer of `glob_script_mem.jpg_task.stream` sits in the same global SCRIPT_MEM block, past `boundary`, past `draw`, past `scale`, past `xp`, past `yp`. The overflow path crosses that distance with attacker-supplied bytes.\n\nWhat makes the bytes attacker-supplied: the entire suffix of `Content-Type` after `=` is taken verbatim. The HTTP server controls header values. There is no length cap on `Content-Type` at the HTTPClient layer. The boundary value can be a kilobyte; `strcpy` will copy a kilobyte.\n\nWhat makes the overwrite reachable: after `fetch_jpg(0, ...)` returns, the script keeps the connection open and calls back into `fetch_jpg()` with selector `2` to pull each frame. Selector `2` invokes `glob_script_mem.jpg_task.http.connected()`, then reads from `glob_script_mem.jpg_task.stream` repeatedly. Both calls dispatch through the vtable pointers the overflow just rewrote. The first virtual call after the corrupted return from selector `0` is the call into attacker-controlled bytes interpreted as a function pointer.\n\nThe PoC's `--mode rce` writes `0x41414141` into that slot. That is not RCE; it is a controlled fault address on ESP32. The vector lands, the device reboots with `Guru Meditation Error`, and the attacker has demonstrated reach. Closing the gap to actual code execution requires picking real Xtensa addresses for a target firmware build and threading the vtable to land in attacker-staged bytes elsewhere in memory. The PoC's README claims CVSS 9.8 Critical and labels its `crash` and `info` modes as RCE primitives. NVD assigned 7.3 with L/L/L impact and is more honest about what the artifact actually demonstrates.\n\n## The same commit fixed two things. The message named one.\n\nThe patch commit's title is `Fix scripter buffer overflow`, singular. The diff has two hunks:\n\n```diff\n@@ -2770,7 +2770,7 @@ int32_t fetch_jpg(uint32_t sel, char *url, uint32_t xp, uint32_t yp, uint32_t sc\n String boundary = glob_script_mem.jpg_task.http.header(headerKeys[0]);\n char *cp = strchr(boundary.c_str(), '=');\n if (cp) {\n- strcpy(glob_script_mem.jpg_task.boundary,cp + 1);\n+ strlcpy(glob_script_mem.jpg_task.boundary, cp + 1, sizeof(glob_script_mem.jpg_task.boundary));\n }\n@@ -2806,7 +2806,7 @@ int32_t fetch_jpg(uint32_t sel, char *url, uint32_t xp, uint32_t yp, uint32_t sc\n glob_script_mem.jpg_task.stream.readBytesUntil('\\n', inbuff, sizeof(inbuff));\n //AddLog(LOG_LEVEL_INFO, PSTR(\"size = %s\"), inbuff);\n char *cp = strchr(inbuff, ':');\n- uint16_t size = 0;\n+ uint32_t size = 0;\n if (cp) {\n size = atoi(cp + 1);\n```\n\nThe first hunk is CVE-2026-38426. The second hunk is the per-frame `Content-Length` parser in selector `2`. Pre-patch, `size` is `uint16_t` and `atoi` returns `int`. An attacker MJPEG server stating `Content-Length: -1` produces `atoi(cp+1) == -1`, an implicit conversion that lands `65535` in the `uint16_t`. The next lines:\n\n```cpp\nif (size > 0) {\n uint8_t *buff = (uint8_t *)special_malloc(size);\n if (buff) {\n glob_script_mem.jpg_task.stream.readBytes(buff, size);\n }\n ...\n}\n```\n\n`special_malloc(65535)` on a busy ESP32 may succeed or may fail; if it succeeds, the device blocks reading 65535 bytes from an attacker connection. Post-patch, the same `-1` produces `0xFFFFFFFF` in `uint32_t`, `special_malloc(4294967295)` returns NULL, the `if (buff)` gate catches it, and the malformed Content-Length becomes a no-op. This change has its own threat model and its own pre-patch behavior. It is not in the CVE record.\n\nThe commit message names one fix. The diff ships two. The maintainer saw the second issue while patching the first and addressed it in the same change without renaming the commit. The function had two undertested size-handling sites; one had its CVE, one did not.\n\n## The author knew strlcpy. The file proves it.\n\nThis file is 14,000+ lines of scripter implementation, parser, web UI handlers, MQTT command dispatch, MJPEG stream handler, embedded HTTP server, mDNS announcer, and forty other features compiled in or out by macro. The author calls `strlcpy` 57 times. They know the bounded copy primitive exists and they use it as their default for copying strings into stack and struct buffers. Twenty-seven of the 57 sites pass `sizeof(dst)` as the size argument; the rest pass a named constant or a tracked variable.\n\nThe same file calls raw `strcpy` 29 times. Each site picks `strcpy` over `strlcpy` for one of two reasons: the destination is alleged to be large enough by some unrelated bound, or the author was not thinking about it. Three of those 29 sites:\n\n```cpp\n// line 873, inside the numeric formatter\nstrcat(cpbuf,nbuff);\nstrcpy(nbuff,cpbuf);\n\n// line 2974, inside a string-variable sort\nstrcpy(temp, s1);\nstrcpy(s1, s2);\nstrcpy(s2, temp);\n\n// line 6865, inside the UDP send command\nchar payload[SCRIPT_MAX_SBSIZE * 3];\nchar part1[SCRIPT_MAX_SBSIZE];\nlp = GetStringArgument(lp, OPER_EQU, part1, 0);\nstrcpy(payload, part1);\n```\n\nThe numeric-formatter one is bounded by the format width. The sort-swap one trusts that all string variables share the same `max_ssize`. The UDP-send one allocates `payload` at three times the part size, which means three sequential `strcat` calls following are within bounds. Each of these is defensible by reading the surrounding code carefully. None of them have been audited by a CVE; CVE-2026-38426 is the only one that has. The next one will be the next site where an `strcpy` destination is sized for a polite caller and the actual caller is the network.\n\n## The threat model is not \"an exposed Tasmota\"\n\nReaching `fetch_jpg()` requires the Tasmota device to run a script containing `jpg(0, \"host/stream\", ...)`. Scripts are loaded through `HandleScriptConfiguration`, which calls `HttpCheckPriviledgedAccess()` before doing anything. An unauthenticated remote attacker cannot push a script. The CVE's CVSS vector says PR:N; the privilege required to write the script is real.\n\nWhat an unauthenticated attacker can do is be on the other side of the URL the admin already wrote. The documented use case for `jpg(0, ...)` is pulling an MJPEG stream from a network IP camera, the kind of camera the Tasmota device is supposed to display on its attached screen. The relevant population is Tasmota devices already scripted to fetch from `cam.local/stream` or `cam.lan:8080`, where the LAN camera is the kind of consumer device that has its own CVE catalog three rows deep.\n\nWhen the camera is compromised, the camera's HTTP responses are attacker-chosen. When the LAN's DNS is hijacked, the URL resolves to attacker infrastructure. When the upstream feed is an internet-reachable MJPEG aggregator, the aggregator chooses the boundary. None of these require the attacker to touch the Tasmota at all. The exploit primitive is held by whoever holds the upstream HTTP endpoint. CVE-2026-38426 turns \"your IP camera got popped\" into \"your Tasmota got popped seven seconds later.\"\n\n## The line was wrong. The file is still next to it.\n\nThe patch closes the one `strcpy` whose destination was forty bytes and whose source was the network. The commit message names that one. The same commit silently tightens a sibling issue in the same function. The other 28 `strcpy` calls remain. Each of them is bounded by an argument the surrounding code chose; the choosing was done by the same author who chose `strlcpy` 57 times.\n\nAudit the 29 by the rule the author followed twice in this commit: where the source can be supplied by something other than the script's own parser, the destination needs `strlcpy(dst, src, sizeof(dst))`. The script's UDP send writes attacker-controllable strings. The web-page handlers write user-supplied form data. The MQTT command dispatch writes broker-supplied topics. Each one is a future CVE shaped like this one, with a different entry path and the same primitive at the destination. The scripter is a design-debt driver, and the choice between `strlcpy` and `strcpy` at each new site is the substrate that keeps producing the class.\n\nPoC: [sermikr0/CVE-2026-38426](https://github.com/sermikr0/CVE-2026-38426).","closing_line":"The author who wrote `strlcpy` fifty-seven times wrote `strcpy` on the line that read from the network. The patch fixes that line. The file is still next to it.","hook_md":"`tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino` is a single file with 57 calls to `strlcpy` and 29 calls to `strcpy`. The author reached for the bounded copy fifty-seven times. CVE-2026-38426 is the line where they reached for `strcpy` instead, on a 40-byte destination buffer adjacent to two C++ network objects, with the source supplied by an HTTP server reachable across the wire.","post_id":510,"slug":"tasmota-cve-2026-38426-strlcpy-fifty-seven-times","title":"CVE-2026-38426: Tasmota's Scripter Calls strlcpy Fifty-Seven Times. The Line That Read From The Network Used strcpy.","type":"initial","unreadable_sentence":"The author who wrote `strlcpy` fifty-seven times wrote `strcpy` on the line that read from the network."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaoYU3wAKCRDeZjl4jgkQ Jlw8AP9RZNUeHvFKDFzpyk1LwYXT0L9l4pPWmBnNBJ3/vyNmsAD+JQM9+y4rKGBP YiHMiGD0sbd3iX6cd0mpbn3SKEQh4Q8= =axwY -----END PGP SIGNATURE-----