Skip to content
Memory corruption Disclosed report Advanced

34: `curl_mprintf` reads `double` for documented `long double` conversions — uninitialized value disclosure

The curl_mprintf family of functions documents that the L length modifier makes floating-point conversions accept a long double, but the implementation always reads a double. On x86-64 this causes an uninitialized floating-point register slot to be read and formatted, disclosing a stale value instead of the supplied long double.

giant_anteater Follow

Originally disclosed on HackerOne

  • Disclosed after 36 hours

Summary

docs/libcurl/curl_mprintf.md documents that the L length modifier makes floating-point conversions (%f, %e, %E, %g, %G) accept a long double argument. The implementation in lib/mprintf.c recognizes L and sets FLAGS_LONGDOUBLE, but the conversion switch (%f/%e/%E/%g/%G) unconditionally selects MTYPE_DOUBLE. The argument is then extracted with va_arg(arglist, double).

On x86-64 (System V ABI), variadic double and long double use different register-save slots. When a caller passes a long double as documented, va_arg(..., double) reads an uninitialized floating-point register slot. Valgrind confirms an uninitialized-value read inside out_double().

Affected commit: c2676bf9e639e31e44b12a2cc82cf2046231b056 (current HEAD at time of report).

Root cause

  1. lib/mprintf.c:261-263 — parse_flags() sets FLAGS_LONGDOUBLE for L.
  2. lib/mprintf.c:397-415 — parse_conversion() maps f/e/E/g/G to MTYPE_DOUBLE without checking FLAGS_LONGDOUBLE.
  3. lib/mprintf.c:617-619 — parsefmt() extracts the argument as va_arg(arglist, double).
  4. lib/mprintf.c:100-108 — struct va_input has no long double member. The enum value MTYPE_LONGDOUBLE exists but is never assigned.

The bug affects all curl_mprintf family functions: curl_mprintf, curl_mfprintf, curl_msprintf, curl_msnprintf, curl_maprintf, and their va_list variants.

Reproduction

Observed output (x86-64 Linux)

sizeof(double)=8 sizeof(long double)=16 DBL_MANT_DIG=53 LDBL_MANT_DIG=64
%.17Lf curl=0.00000000000000000 libc=1.23456789012345679 match=no
%.17Le curl=6.95335579603750720e-310 libc=1.23456789012345679e+00 match=no
%.17LE curl=6.95335579603750720E-310 libc=1.23456789012345679E+00 match=no
%.17Lg curl=6.9533557960375072e-310 libc=1.2345678901234568 match=no
%.17LG curl=6.9533557960375072E-310 libc=1.2345678901234568 match=no
mismatches=5/5
RESULT: VULNERABLE
Conditional jump or move depends on uninitialised value(s)
   at 0x...: out_double (mprintf.c:681)
 Uninitialised value was created by a stack allocation

Suggested fix

In parse_conversion(), when FLAGS_LONGDOUBLE is set alongside a floating-point conversion specifier, assign MTYPE_LONGDOUBLE instead of MTYPE_DOUBLE. Add a long double member to struct va_input, extract with va_arg(arglist, long double), and pass it through the output formatting path.

Impact

A caller following the documented API on x86-64 gets a stale/uninitialized floating-point value formatted instead of the supplied long double. Valgrind confirms the value is uninitialized.

No in-tree production usage of %L floating-point conversions was found in curl or libcurl. The format string and argument originate with the calling application, not from remote input. The practical security impact depends on whether a downstream application formats a long double via curl_mprintf and exposes the result across a trust boundary. I did not identify such a scenario and leave the security classification to the curl team.

The original report as published on HackerOne, by giant_anteater. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the conversion parser sets a long-double flag but never maps floating-point conversions to a long-double type, so the argument is always extracted as a double.

Impact

A caller following the documented API on x86-64 gets a stale or uninitialized floating-point value formatted instead of the supplied long double; the practical security impact depends on whether a downstream application exposes that output across a trust boundary, and no such scenario was identified.

What the attacker needed

X86-64 System V ABI; caller uses %L with a long double; format string controlled by the application

The fix

The conversion parser should assign the long-double type when the long-double flag is set for a floating-point conversion, add a long double member to the argument union, extract it with the matching va_arg type, and pass it through the output path.

How it was found

  1. Call a curl_mprintf family function with a floating-point conversion using the L modifier and a long double argument.
  2. Observe that the output does not match the value produced by the system C library for the same format and argument.
  3. Run the same call under Valgrind and see an uninitialized-value read inside the double output routine.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A formatting function lets a program build text by filling placeholders like %f with numbers. The documentation says a special modifier L lets you pass a higher-precision number (a long double), but the code ignores that and reads a normal double instead. On some systems those two number types are passed in different places, so the function reads leftover data from memory and prints that instead of the number you gave it.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by giant_anteater

View all

93 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.