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

@@ -288,7 +288,6 @@ format_json(ClientMessage__TypeCase event_type,
struct json_container json = { 0 };
struct json_value json_value;
struct timespec ts;
char **strvec;
size_t idx;
debug_decl(format_json, SUDO_DEBUG_UTIL);
@@ -365,20 +364,22 @@ format_json(ClientMessage__TypeCase event_type,
if (!sudo_json_add_value(&json, info->key, &json_value))
goto bad;
break;
case INFO_MESSAGE__VALUE_STRLISTVAL:
/* Must convert to NULL-terminated string vector. */
strvec = strlist_copy(info->strlistval);
if (strvec == NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO|SUDO_DEBUG_LINENO,
"%s: %s", __func__, "unable to allocate memory");
case INFO_MESSAGE__VALUE_STRLISTVAL: {
InfoMessage__StringList *strlist = info->strlistval;
size_t n;
if (!sudo_json_open_array(&json, info->key))
goto bad;
for (n = 0; n < strlist->n_strings; n++) {
json_value.type = JSON_STRING;
json_value.u.string = strlist->strings[n];
if (!sudo_json_add_value(&json, NULL, &json_value))
goto bad;
}
json_value.type = JSON_ARRAY;
json_value.u.array = strvec;
if (!sudo_json_add_value(&json, info->key, &json_value))
if (!sudo_json_close_array(&json))
goto bad;
free(strvec);
break;
}
default:
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unexpected value case %d", info->value_case);

View File

@@ -70,7 +70,7 @@ has_strlistval(InfoMessage *info)
* The input string list need not be NULL-terminated.
* Returns a NULL-terminated string vector.
*/
char **
static char **
strlist_copy(InfoMessage__StringList *strlist)
{
char **dst, **src = strlist->strings;

View File

@@ -188,7 +188,6 @@ int store_suspend(CommandSuspend *msg, struct connection_closure *closure);
int store_winsize(ChangeWindowSize *msg, struct connection_closure *closure);
void iolog_close_all(struct connection_closure *closure);
void iolog_details_free(struct iolog_details *details);
char ** strlist_copy(InfoMessage__StringList *strlist);
/* logsrvd_conf.c */
bool logsrvd_conf_read(const char *path);