-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The comment was right about ten\n\n`preparse` is a DBI method shipped under `$dbh->preparse(...)` starting in DBI 1.21, dated February 7, 2002. The Changes file records it as \"experimental undocumented,\" with thanks to Scott T. Hildreth for much of the work. The function transforms SQL placeholder syntax between dialects: `?` to `:p1`, `:1` to `?`, `:name` to `%s`, controlled by `ps_accept` and `ps_return` flags. DBD drivers call it internally to normalize between the X/Open `?` convention and a backend that wants numbered binders. Application code calls it to do its own SQL rewriting before handing the statement to the driver. Twenty-four years after it landed, it is still experimental, still undocumented, and still callable through `$dbh->preparse`.\n\nThe buffer the function writes its result into is allocated once, at the top of the function:\n\n```c\n/* XXX this allocation strategy won't work when we get to more advanced stuff */\nnew_stmt_sv = newSV(strlen(statement) * 3);\nsv_setpv(new_stmt_sv,\"\");\nsrc = statement;\ndest = SvPVX(new_stmt_sv);\n```\n\n`strlen(statement) * 3` is the entire allocation. There is no per-placeholder accounting and no growth pass. The comment names the allocation strategy and admits the strategy doesn't scale.\n\nThe arithmetic the comment was warning about sits a hundred and fifty lines below, in the `?` branch:\n\n```c\nif (*start == '?') /* X/Open Standard */\n{\n style = \"?\";\n if (PS_return(DBIpp_ph_qm))\n ;\n else if (PS_return(DBIpp_ph_cn)) { /* '?' -> ':p1' (etc) */\n sprintf(start,\":p%d\", idx++);\n dest = start+strlen(start);\n }\n ...\n}\n```\n\nEach `?` in the source is one byte. Each rewritten placeholder is `:p`, where `` is decimal. `:p1` through `:p9` are three bytes each. `:p10` through `:p99` are four bytes. `:p100` through `:p999` are five bytes. The `strlen * 3` allocation is exactly the worst case for `:p1` through `:p9` and runs out at the tenth question mark.\n\nFor a literal input of ten question marks, `strlen` is ten, the allocation is thirty bytes, and the bytes written are `:p1:p2:p3:p4:p5:p6:p7:p8:p9:p10`, which is thirty-one bytes. The thirty-first byte lands one byte past the end of the allocated SV. Each additional `?` beyond ten widens the overflow.\n\nThe author's note from at least 2004, `XXX this allocation strategy won't work when we get to more advanced stuff`, is a written admission from inside the codebase that ten or more `?` would not fit. The \"more advanced stuff\" turned out to be ten question marks.\n\n## The reachable surface\n\nThe CVE record assigns CVSS 9.8 with vector `AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`. The network-attack-vector rating is generous for a Perl library method; defending it requires noting that DBD drivers invoke `preparse` internally during SQL normalization, and any Perl application that hands attacker-influenced SQL strings through `DBI` reaches the same `newSV(strlen(statement) * 3)` line through the driver layer. The 1.22 Changes entry (\"Extended t/preparse.t and removed `use Devel::Peek` thanks to Scott Hildreth\") records the function as part of the project's regular test surface from its second release.\n\nThe bytes that fall off the end of the allocated SV land in the heap allocator's next block. CWE-787 (out-of-bounds write) is the CVE's classification. The exploitation primitive is \"attacker chooses how many extra bytes to write past a heap allocation by varying the number of `?` characters in the SQL string.\" The primitive's input is a count, and the count is bounded by the source string's length.\n\n## The patch is one line\n\nH.Merijn Brand's commit `af79036c07aa9a457971c0f4136e37c85dc20978`, dated May 28, 2026, changes one line in DBI.xs:\n\n```diff\n@@ -4203,7 +4203,7 @@ preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo)\n }\n\n /* XXX this allocation strategy won't work when we get to more advanced stuff */\n- new_stmt_sv = newSV(strlen(statement) * 3);\n+ new_stmt_sv = newSV(strlen(statement) * 6 + 16);\n sv_setpv(new_stmt_sv,\"\");\n src = statement;\n dest = SvPVX(new_stmt_sv);\n```\n\nThe commit message reads:\n\n> Replacing `?` with `:p#` in `preparse ()` with more than 9 `?` causes buffer overflow\n>\n> `:p1` is length 3, `?` just 1, but `:p1003` is length 6!\n\nThe diff has no other changes to `DBI.xs`. The Changes file entry, added in the same release, reads \"Fix possible buffer overflow in preparse (CVE-2026-10879).\" The XXX comment on the line above the allocation, the comment that names the limitation, is unchanged. The patch raises the multiplier and ships.\n\n## The threshold moved from ten to 11,123\n\nThe new allocation is `strlen(statement) * 6 + 16`. The same `?` to `:p` arithmetic applies. For an input of N question marks:\n\n- placeholders 1 through 9 cost 3 bytes each (`:p1` through `:p9`)\n- placeholders 10 through 99 cost 4 bytes each\n- placeholders 100 through 999 cost 5 bytes each\n- placeholders 1,000 through 9,999 cost 6 bytes each\n- placeholders 10,000 through 99,999 cost 7 bytes each\n\nSum for the first 9,999 placeholders: `9*3 + 90*4 + 900*5 + 9000*6 = 58,887` bytes. The post-patch allocation for `strlen = 9,999` is `6 * 9999 + 16 = 60,010` bytes. The cushion is 1,123 bytes.\n\nIn the range 10,000 to 99,999, each additional `?` adds 7 bytes of output, while the allocation adds 6 bytes per `strlen` byte. The 1,123-byte cushion shrinks at one byte per additional placeholder.\n\nAt N = 11,123 question marks, the cushion runs out. The bytes written equal `27 + 360 + 4500 + 54000 + (11123 - 9999)*7 = 66,755`. The allocation equals `6 * 11123 + 16 = 66,754`. The overflow is one byte. Beyond that, the overflow grows by one byte per additional `?` until the next decimal-digit boundary at 100,000 placeholders, where it grows by two bytes per additional `?`.\n\nThe patch raised the threshold from ten placeholders to 11,123 placeholders. The structural shape of the bug, `newSV(strlen(statement) * )` written into by `sprintf(\":p%d\", idx)` with no per-placeholder accounting, is unchanged. The XXX comment three lines above is unchanged because it is still right.\n\n## The comment is the codebase telling you about itself\n\nThis is the [todo-that-shipped](/patterns/todo-that-shipped) pattern in its long-clock form. The catalog's exhibit on [Cockpit's CVE-2026-4802](/posts/cockpit-cve-2026-4802-the-todo-named-the-fix) carried a comment for sixty-one months; [free5GC's CVE-2026-44315](/posts/free5gc-cve-2026-44315-oauth-outbound-todo-inbound) carried four `// TODO: Authorize the AF` comments for five years and five months. DBI's `XXX this allocation strategy won't work when we get to more advanced stuff` has been in the public source tree since at least February 1, 2004, the date of the SVN import that initialized git history for the project. The comment is at minimum twenty-two years and four months old. The `preparse` function and its allocation site were both shipped in DBI 1.21 on February 7, 2002, which puts the plausible upper bound on the comment's age at twenty-four years and four months. The CVE record names the bug class the comment described.\n\nIt is also [default-is-the-mitigation](/patterns/default-is-the-mitigation). The catalog's other exhibit, [vLLM's CVE-2026-5497](/posts/vllm-cve-2026-5497-the-fix-is-the-default), lands the safer default and the unbounded opt-out in one commit; the opt-out is a request kwarg. DBI's patch is the same shape with a fixed constant in place of a config knob. The safer default is `6 + 16`. The \"opt-out\" is \"supply more than 11,122 `?` characters.\" There is no opt-out flag because there is no opt-out gate; the caller's only knob is the input length. The patched binary contains the unpatched primitive, and the size at which the primitive activates has moved from ten to eleven thousand.\n\nThe 2004 comment, the 2026 patch, and the 11,123-placeholder threshold are three statements about the same code. They agree. The allocation strategy does not scale. The patch picked a number large enough to push the next failure past most practical SQL strings an application would normalize today, and left the comment in place because the comment is still describing what the file does.\n\nPoC: [oss-security advisory](https://seclists.org/oss-sec/2026/q2/825). Patch: [commit af79036](https://github.com/perl5-dbi/dbi/commit/af79036c07aa9a457971c0f4136e37c85dc20978.patch).","closing_line":"Twenty-two years ago the file said the allocation strategy wouldn't scale. The 2026 patch raised the multiplier from three to six. The comment three lines above the allocation is still in the file because it is still right.","hook_md":"DBI.xs line 4205 has carried the comment `/* XXX this allocation strategy won't work when we get to more advanced stuff */` since at least February 1, 2004. The line directly below it allocates `strlen(statement) * 3` bytes for a destination buffer and then writes `:p%d` numbered binders into it. The 2026 patch changes the line below the comment from `* 3` to `* 6 + 16` and ships. The comment is unchanged. \"More advanced stuff\" turned out to be ten question marks.","post_id":607,"slug":"dbi-cve-2026-10879-xxx-comment-was-right-twice","title":"CVE-2026-10879: DBI's XXX Comment Said the Allocation Wouldn't Scale. The Patch Raised the Multiplier and Left the Comment.","type":"initial","unreadable_sentence":"The patch raised the threshold from ten placeholders to 11,123, and left the XXX comment that said the allocation strategy wouldn't scale unchanged three lines above, because it is still right."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCas029AAKCRDeZjl4jgkQ JkKDAQCM5urMLDvEU66qvcfAFINRQOrCrw3e4OvQ8TXFSEJ8rwEArV/G/UwpjFHh P/E8If9wbZf37LOiF6CsznRo7bk9eg8= =Jl0F -----END PGP SIGNATURE-----