Do not use JSON_ARRAY with sudo_json_add_value()

This commit is contained in:
Todd C. Miller
2020-03-29 05:05:08 -06:00
parent f24dacdee2
commit cffda82e20
7 changed files with 48 additions and 59 deletions

View File

@@ -258,12 +258,23 @@ add_key_value(struct json_container *json, const char *str)
static bool
add_array(struct json_container *json, const char *name, char * const * array)
{
const char *cp;
struct json_value json_value;
debug_decl(add_array, SUDO_DEBUG_PLUGIN);
json_value.type = JSON_ARRAY;
json_value.u.array = array;
debug_return_bool(sudo_json_add_value(json, name, &json_value));
if (!sudo_json_open_array(json, name))
debug_return_bool(false);
while ((cp = *array) != NULL) {
json_value.type = JSON_STRING;
json_value.u.string = cp;
if (!sudo_json_add_value(json, name, &json_value))
debug_return_bool(false);
array++;
}
if (!sudo_json_close_array(json))
debug_return_bool(false);
debug_return_bool(true);
}
static bool