From 1429814edaad1f5b81bca927730857ce12df40f8 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Sat, 1 Oct 2022 17:53:11 -0500 Subject: [PATCH] base: HEIM_JSON_F_TRY_DECODE_DATA cannot work The idea with HEIM_JSON_F_TRY_DECODE_DATA is that on parsing of JSON texts, if we find a base64-encoded string, decode it. But a lot of strings that aren't base64-encoded can be decoded anyways, leaving a mess. Insted we should -in a future commit- implement this only for the string values of "heimdal-type-data-76d7fca2-d0da-4b20-a126-1a10f8a0eae6" names in singleton objects. --- lib/base/json.c | 29 ----------------------------- lib/base/test_base.c | 7 ------- 2 files changed, 36 deletions(-) diff --git a/lib/base/json.c b/lib/base/json.c index 794aee425..a4ca83845 100644 --- a/lib/base/json.c +++ b/lib/base/json.c @@ -43,8 +43,6 @@ static heim_base_once_t heim_json_once = HEIM_BASE_ONCE_INIT; static heim_string_t heim_tid_data_uuid_key = NULL; -static const char base64_chars[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static void json_init_once(void *arg) @@ -983,33 +981,6 @@ parse_string(struct parse_ctx *ctx) return o; } - /* If we can decode as base64, then let's */ - if (ctx->flags & HEIM_JSON_F_TRY_DECODE_DATA) { - void *buf; - size_t len = p - p0; - - if (len > 0) - len--; - - if (len >= 4 && strspn(p0, base64_chars) >= len - 2) { - buf = malloc(len); - if (buf == NULL) { - ctx->error = heim_error_create_enomem(); - free(p0); - return NULL; - } - len = rk_base64_decode(p0, buf); - if (len > -1) { - /* Yes base64, return the decoded data */ - o = heim_data_ref_create(buf, len, free); - free(p0); - return o; - } - /* Not base64, so return what we had */ - free(buf); - } - } - /* Sadly this will copy `p0' */ o = heim_string_create_with_bytes(p0, p - p0); free(p0); diff --git a/lib/base/test_base.c b/lib/base/test_base.c index e26de0905..6d0668663 100644 --- a/lib/base/test_base.c +++ b/lib/base/test_base.c @@ -525,13 +525,6 @@ test_json(void) "wrong data NUL"); o2 = heim_json_copy_serialize(o, 0, NULL); heim_assert(o2 != NULL, "data not serialized"); - o3 = heim_json_create(heim_string_get_utf8(o2), 10, - HEIM_JSON_F_TRY_DECODE_DATA, NULL); - heim_assert(o3 != NULL, "data not accepted"); - heim_assert(heim_data_get_length(o3) == 1, "wrong data length"); - heim_assert(((const char *)heim_data_get_ptr(o3))[0] == '\0', - "wrong data NUL"); - heim_release(o3); heim_release(o2); heim_release(o);