//nefariousplan

CVE-2026-10879: DBI's XXX Comment Said the Allocation Wouldn't Scale. The Patch Raised the Multiplier and Left the Comment.

vendor

patterns

cve

proof of concept

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.

The comment was right about ten

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.

The buffer the function writes its result into is allocated once, at the top of the function:

/* XXX this allocation strategy won't work when we get to more advanced stuff */
new_stmt_sv = newSV(strlen(statement) * 3);
sv_setpv(new_stmt_sv,"");
src  = statement;
dest = SvPVX(new_stmt_sv);

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.

The arithmetic the comment was warning about sits a hundred and fifty lines below, in the ? branch:

if (*start == '?')              /* X/Open Standard */
{
    style = "?";
    if (PS_return(DBIpp_ph_qm))
        ;
    else if (PS_return(DBIpp_ph_cn)) { /* '?' -> ':p1' (etc) */
        sprintf(start,":p%d", idx++);
        dest = start+strlen(start);
    }
    ...
}

Each ? in the source is one byte. Each rewritten placeholder is :p<idx>, where <idx> 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.

For 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.

The 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.

The reachable surface

The 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.

The 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.

The patch is one line

H.Merijn Brand's commit af79036c07aa9a457971c0f4136e37c85dc20978, dated May 28, 2026, changes one line in DBI.xs:

@@ -4203,7 +4203,7 @@ preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo)
     }

     /* XXX this allocation strategy won't work when we get to more advanced stuff */
-    new_stmt_sv = newSV(strlen(statement) * 3);
+    new_stmt_sv = newSV(strlen(statement) * 6 + 16);
     sv_setpv(new_stmt_sv,"");
     src  = statement;
     dest = SvPVX(new_stmt_sv);

The commit message reads:

Replacing ? with :p# in preparse () with more than 9 ? causes buffer overflow

:p1 is length 3, ? just 1, but :p1003 is length 6!

The 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.

The threshold moved from ten to 11,123

The new allocation is strlen(statement) * 6 + 16. The same ? to :p<idx> arithmetic applies. For an input of N question marks:

  • placeholders 1 through 9 cost 3 bytes each (:p1 through :p9)
  • placeholders 10 through 99 cost 4 bytes each
  • placeholders 100 through 999 cost 5 bytes each
  • placeholders 1,000 through 9,999 cost 6 bytes each
  • placeholders 10,000 through 99,999 cost 7 bytes each

Sum 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.

In 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.

At 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 ?.

The patch raised the threshold from ten placeholders to 11,123 placeholders. The structural shape of the bug, newSV(strlen(statement) * <fixed-constant>) 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.

The comment is the codebase telling you about itself

This is the todo-that-shipped pattern in its long-clock form. The catalog's exhibit on Cockpit's CVE-2026-4802 carried a comment for sixty-one months; free5GC's CVE-2026-44315 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.

It is also default-is-the-mitigation. The catalog's other exhibit, vLLM's CVE-2026-5497, 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.

The 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.

PoC: oss-security advisory. Patch: commit af79036.

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.