Fix string length measurement for strings in icons; if the string came from the templates file, it will be LF terminated, not NUL terminated. Therefore, use a strlen variant that terminates on control characters, rather than just \0. This prevents reading memory beyond the end of the string.

svn path=/trunk/netsurf/; revision=3475
This commit is contained in:
John Mark Bell 2007-08-04 11:47:40 +00:00
parent 86d0dd8563
commit c1531c449f
1 changed files with 21 additions and 1 deletions

View File

@ -31,6 +31,7 @@
static void ro_gui_wimp_cache_furniture_sizes(wimp_w w);
static size_t ro_gui_strlen(const char *str);
static wimpextend_furniture_sizes furniture_sizes;
static wimp_w furniture_window = NULL;
@ -265,7 +266,7 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) {
}
/* copy the text across */
old_len = strlen(ic.icon.data.indirected_text.text);
old_len = ro_gui_strlen(ic.icon.data.indirected_text.text);
if (ic.icon.data.indirected_text.size) {
strncpy(ic.icon.data.indirected_text.text,
local_text ? local_text : text,
@ -944,3 +945,22 @@ bool ro_gui_wimp_check_window_furniture(wimp_w w, wimp_window_flags mask) {
}
return state.flags & mask;
}
/**
* RO GUI-specific strlen, for control character terminated strings
*
* \param str The string to measure the length of
* \return The length of the string
*/
size_t ro_gui_strlen(const char *str)
{
size_t len = 0;
if (str == NULL)
return 0;
while (*(str++) >= ' ')
len++;
return len;
}