← ALL ADVISORIES

LOW BYTERAY-2026-0486Disclosed

wolfSSL — Non-Const Exported Pointer mp_s_rmap in Heap Math Radix Conversion

The heap math backend exports its radix alphabet as const char *mp_s_rmap: the characters are const but the pointer is writable. Code in the same process can repoint it, and mp_read_radix and mp_toradix index it over a fixed 64 entries without checking the length, which reads past a shorter replacement and corrupts conversions.

Advisory
BYTERAY-2026-0486
CWE
CWE-500
CVSS
3.9 (CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:L/I:L/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds using the heap math integer backend (USE_INTEGER_HEAP_MATH, --enable-heapmath)
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The heap-based big-integer implementation in wolfCrypt converts numbers to and from text with a 64-character lookup table, mp_s_rmap. It maps digit values 0 to 63 to the characters 0-9, A-Z, a-z, + and /.

The table is declared as const char *. That makes the characters constant but leaves the pointer itself writable, and the pointer is declared extern in a public header. Any code linked into the process can point it at a different string.

The conversion routines always index the table over a fixed range of 64 entries and never check how long the current string is. If the pointer is redirected to a shorter string, parsing and printing read past its end and produce wrong numbers. There is no remote path to the pointer; changing it needs an in-process write. The default SP math backend does not compile this code.

Affected Products and Versions

  • Component: wolfcrypt/src/integer.c, mp_s_rmap, mp_read_radix() and mp_toradix(); declaration in wolfssl/wolfcrypt/integer.h.
  • Required build: the heap math backend, USE_INTEGER_HEAP_MATH without USE_FAST_MATH (wolfcrypt/src/integer.c:31), selected with --enable-heapmath.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default build uses SP math and does not compile this file (configure.ac:474-477). The fast math backend keeps its equivalent table file-static (wolfcrypt/src/tfm.c:5660).
  • Other releases were not checked.

Technical Details

The definition (wolfcrypt/src/integer.c:5288-5290):

/* chars used in radix conversions */
const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                        "abcdefghijklmnopqrstuvwxyz+/";

The header declares it as extern const char *mp_s_rmap; (wolfssl/wolfcrypt/integer.h:311). The const applies to the pointed-to characters. The pointer is ordinary writable data with external linkage.

The consumers:

  1. mp_read_radix() accepts a radix from 2 to 64 and, for each input character, scans mp_s_rmap[y] for y from 0 to 63 (wolfcrypt/src/integer.c:5328-5332). The scan covers all 64 entries regardless of the radix or of the length of the string the pointer refers to.
  2. mp_toradix() writes mp_s_rmap[d] for each digit d below the radix (wolfcrypt/src/integer.c:5485) and mp_s_rmap[0] for hexadecimal padding (wolfcrypt/src/integer.c:5491).

If the pointer refers to a string shorter than 64 characters, the scan in mp_read_radix() reads beyond the terminator whenever the input character is not found earlier, and mp_toradix() reads beyond it for larger digit values. With any replacement alphabet, parsed values and printed strings no longer correspond.

No function in the tree writes the pointer after its initialization and no accessor guards it.

Reachability and Preconditions

  • Build with the heap math backend.
  • An in-process writer: a separate memory-corruption bug that gives a write primitive, or a malicious or faulty component linked into the same process.
  • The application then parses or prints a big integer in text form through mp_read_radix() or mp_toradix().
  • No remote path modifies the pointer.

Impact

The pointer is an amplifier for an attacker who can already write memory in the process. Redirecting it yields out-of-bounds reads in radix conversion and incorrect results when numbers are parsed from or printed to text. It does not give an attacker a way into the process.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.

The fix direction is to make the pointer itself constant: const char * const mp_s_rmap in the definition and in the extern declaration, so the pointer is placed in read-only data. The consumers can also bound their loops by the radix and not by the fixed 64. Projects that do not need the heap math backend can use the default SP math backend or fast math. Neither exports this symbol.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References