diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2015-11-09 16:21:33 +0100 |
---|---|---|
committer | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2015-11-09 16:21:33 +0100 |
commit | 0188c1fb5d85fa0dc05114afaff44ff0aa9d7f87 (patch) | |
tree | 5046450764eb4a786b6499f48bf8b67f589d7a5d /src/core | |
parent | 50775e92e64561837e6c805fc8fef19aedaafeb4 (diff) | |
parent | b054ade4b90a05d778a64c63c0c834a126884aaa (diff) | |
download | irssi-0188c1fb5d85fa0dc05114afaff44ff0aa9d7f87.zip |
Merge pull request #341 from dequis/strsplit-len-fix
Fix invalid reads in strsplit_len when splitting on spaces
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/misc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/core/misc.c b/src/core/misc.c index 88c27255..490b5a8f 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -997,22 +997,22 @@ char **strsplit_len(const char *str, int len, gboolean onspace) int n; int offset; - for (n = 0; *str != '\0'; n++, str += MIN(len - offset, strlen(str))) { - offset = 0; - if (onspace) { + for (n = 0; *str != '\0'; n++, str += offset) { + offset = MIN(len, strlen(str)); + if (onspace && strlen(str) > len) { /* * Try to find a space to split on and leave * the space on the previous line. */ int i; - for (i = 0; i < len; i++) { - if (str[len-1-i] == ' ') { + for (i = len - 1; i > 0; i--) { + if (str[i] == ' ') { offset = i; break; } } } - ret[n] = g_strndup(str, len - offset); + ret[n] = g_strndup(str, offset); ret = g_renew(char *, ret, n + 2); } ret[n] = NULL; |