Skip to content

Refuse raw:hex: keys with non-hex characters, avoid an over-read - #313

Merged
utelle merged 2 commits into
utelle:mainfrom
SchwarzDigits:fix/raw-key-checks
Nov 17, 2026
Merged

utelle merged 2 commits into
utelle:mainfrom
SchwarzDigits:fix/raw-key-checks

Conversation

@mtrossbach

Copy link
Copy Markdown
Contributor

Two small fixes in sqlite3mcExtractRawKey, as discussed by mail:

  • After "raw:hex:" only the length was checked. Non-hex characters were converted as 0, so "raw:hex:" followed by 64 times "z" gave an all-zero key without an error. The value is now accepted only if it is hex.
  • The check for the secondary prefixes "bin:" and "hex:" read 4 bytes even if fewer followed "raw:", up to 3 bytes past the end of a key passed without a terminating zero (for example "raw:b" with length 5).

cryptotest gets a section for raw keys: valid values with raw:hex:, raw:bin: and raw:, with and without salt, a 128-bit hex key whose length equals key plus salt in binary form, and invalid values (wrong length, non-hex characters after raw:hex:, too short). Each key is passed in a buffer of its exact length.

Testing (macOS arm64, flags from Makefile.am):

  • cryptotest passes, also with ASan and UBSan.
  • On e65527d without the fix, the check for "raw:hex:zzz..." fails, and with ASan the test stops at the over-read (heap-buffer-overflow in sqlite3mcExtractRawKey).

sqlite3mcExtractRawKey accepted a value after "raw:hex:" if only its
length matched; non-hex characters were converted as 0, so for example
"raw:hex:" followed by 64 times "z" gave an all-zero key without an
error. Check isHex as well.

The test for the secondary prefixes read 4 bytes even if fewer than 4
followed "raw:", up to 3 bytes past the end of a key passed without a
terminating zero (for example "raw:b" with length 5).
Valid values with raw:hex:, raw:bin: and raw:, with and without salt, a
128-bit hex key that has the length of key plus salt in binary form, and
invalid values (wrong length, non-hex characters after raw:hex:, too
short), each passed in a buffer of its exact length.
@utelle
utelle merged commit a5058ce into utelle:main Nov 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants