mirror of
https://github.com/irssi/irssi.git
synced 2024-09-01 04:14:16 -04:00
Merge pull request #341 from dequis/strsplit-len-fix
Fix invalid reads in strsplit_len when splitting on spaces
This commit is contained in:
commit
0188c1fb5d
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user