sd-json: when parsing optionally insist top-level variant is object or array
Typically, the top-level JSON object has to be an object, in any json document we parse, hence let's add a simple way to enforce that. Make use of this in various places. (Note, various other JSON parsers insist on this logic right from the beginning, but I actually thinking making this insisting optional like this patch does it is the cleaner approach)
This commit is contained in:
committed by
Daan De Meyer
parent
bc6380ae07
commit
2c74a91cb8
@@ -162,7 +162,7 @@ _public_ int cryptsetup_token_validate(
|
||||
|
||||
assert(json);
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Could not parse " TOKEN_NAME " json object: %m.");
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ _public_ int cryptsetup_token_validate(
|
||||
sd_json_variant *w;
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Could not parse " TOKEN_NAME " json object: %m.");
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ _public_ int cryptsetup_token_open_pin(
|
||||
if (usrptr)
|
||||
params = *(systemd_tpm2_plugin_params *)usrptr;
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Failed to parse token JSON data: %m");
|
||||
|
||||
@@ -186,7 +186,7 @@ _public_ void cryptsetup_token_dump(
|
||||
|
||||
assert(json);
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return (void) crypt_log_debug_errno(cd, r, "Failed to parse " TOKEN_NAME " JSON object: %m");
|
||||
|
||||
@@ -275,7 +275,7 @@ _public_ int cryptsetup_token_validate(
|
||||
|
||||
assert(json);
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_debug_errno(cd, r, "Could not parse " TOKEN_NAME " json object: %m");
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ int parse_luks2_fido2_data(
|
||||
assert(ret_cid_size);
|
||||
assert(ret_required);
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return crypt_log_error_errno(cd, r, "Failed to parse JSON token data: %m");
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ int parse_luks2_pkcs11_data(
|
||||
assert(ret_encrypted_key);
|
||||
assert(ret_encrypted_key_size);
|
||||
|
||||
r = sd_json_parse(json, 0, &v, NULL, NULL);
|
||||
r = sd_json_parse(json, SD_JSON_PARSE_MUST_BE_OBJECT, &v, /* reterr_line= */ NULL, /* reterr_column= */ NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user