mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +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:
parent
216b232946
commit
5010ca2c99
@ -420,11 +420,7 @@ static char* next_line(char *s, unsigned int *max, char **color_out)
|
|||||||
last_space = i;
|
last_space = i;
|
||||||
sequence_len = l_utf8_get_codepoint(&s[i], s_len - i,
|
sequence_len = l_utf8_get_codepoint(&s[i], s_len - i,
|
||||||
&w);
|
&w);
|
||||||
if (sequence_len < 0) {
|
sequence_columns = wcwidth(w);
|
||||||
sequence_len = 1;
|
|
||||||
sequence_columns = 1;
|
|
||||||
} else
|
|
||||||
sequence_columns = wcwidth(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compensate max bytes */
|
/* Compensate max bytes */
|
||||||
@ -532,9 +528,17 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
|
|||||||
|
|
||||||
for (i = 0; i < ncolumns; i++) {
|
for (i = 0; i < ncolumns; i++) {
|
||||||
struct table_entry *e = &entries[i];
|
struct table_entry *e = &entries[i];
|
||||||
|
char *v;
|
||||||
|
|
||||||
e->width = va_arg(va, unsigned int);
|
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);
|
str += entry_append(e, str);
|
||||||
}
|
}
|
||||||
@ -565,9 +569,13 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
|
|||||||
str = buf;
|
str = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
for (i = 0; i < ncolumns; i++) {
|
for (i = 0; i < ncolumns; i++) {
|
||||||
if (entries[i].color)
|
if (entries[i].color)
|
||||||
l_free(entries[i].color);
|
l_free(entries[i].color);
|
||||||
|
|
||||||
|
if (entries[i].next)
|
||||||
|
l_free(entries[i].next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user