fix(json): reject malformed hex input

Reject odd-length and non-hex strings before decoding them.

Tested: 1796 ASan/UBSan tests in amalgamated and unamalgamated builds
This commit is contained in:
94xhn committed 2026-07-16 08:33:06 +08:00
1 parent bc69625a5e
commit dc52d8b1dc
5 files changed
+29 -13

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ char *mg_json_get_str(struct mg_str json, const char *path);
// Decodes a hex-encoded JSON string at path into a heap-allocated byte array.
// Sets *len to the decoded byte count. Caller must mg_free() the result.
// Returns NULL if not found or not a string.
// Returns NULL if not found, not a string, or not valid hexadecimal.
char *mg_json_get_hex(struct mg_str json, const char *path, int *len);
// Decodes a base64-encoded JSON string at path into a heap-allocated byte