3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 09:39:25 +01:00

client: validate utf-8 before displaying row

In theory any input to this function should have valid utf-8 but
just in case the strings should be validated. This removes the
need to check the return of l_utf8_get_codepoint which is useful
since there is no graceful failure path at this point.
This commit is contained in:
James Prestwood 2022-10-12 11:35:19 -07:00 committed by Denis Kenzior
parent 216b232946
commit 5010ca2c99

View File

@ -420,11 +420,7 @@ static char* next_line(char *s, unsigned int *max, char **color_out)
last_space = i;
sequence_len = l_utf8_get_codepoint(&s[i], s_len - i,
&w);
if (sequence_len < 0) {
sequence_len = 1;
sequence_columns = 1;
} else
sequence_columns = wcwidth(w);
sequence_columns = wcwidth(w);
}
/* Compensate max bytes */
@ -532,9 +528,17 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
for (i = 0; i < ncolumns; i++) {
struct table_entry *e = &entries[i];
char *v;
e->width = va_arg(va, unsigned int);
e->next = l_strdup(va_arg(va, char*));
v = va_arg(va, char *);
if (!l_utf8_validate(v, strlen(v), NULL)) {
display_error("Invalid utf-8 string!");
goto done;
}
e->next = l_strdup(v);
str += entry_append(e, str);
}
@ -565,9 +569,13 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
str = buf;
}
done:
for (i = 0; i < ncolumns; i++) {
if (entries[i].color)
l_free(entries[i].color);
if (entries[i].next)
l_free(entries[i].next);
}
}