diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2007-08-04 11:47:40 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2007-08-04 11:47:40 +0000 |
commit | c1531c449f511702d7312c3a88aede46ac195597 (patch) | |
tree | 3a0a2509523244093f8ad97ae83cbaef42834c43 /riscos | |
parent | 86d0dd8563392e81f2ef18a290637dbda06e9c4d (diff) | |
download | netsurf-c1531c449f511702d7312c3a88aede46ac195597.tar.gz netsurf-c1531c449f511702d7312c3a88aede46ac195597.tar.bz2 |
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
Diffstat (limited to 'riscos')
-rw-r--r-- | riscos/wimp.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/riscos/wimp.c b/riscos/wimp.c index df47a7a1e..cca0adf94 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -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; +} |