diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-06-21 00:20:54 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-06-21 00:20:54 +0200 |
commit | ad7fdd4bf80b716ba438e59e66d27bba8e7acefb (patch) | |
tree | d89c4064c9982032b431cffea138a621237ae835 | |
parent | 3a72c90c2f7348f3e989a8cbe557a99c6de0e026 (diff) |
util: fix parseline crash
-rw-r--r-- | util.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -72,6 +72,7 @@ printlink(const char *link, const char *baseurl, FILE *fp) /* read a field-separated line from 'fp', * separated by a character 'separator', * 'fields' is a list of pointer with a maximum size of 'maxfields'. + * 'maxfields' must be > 0. * 'line' buffer is allocated using malloc, 'size' will contain the * allocated buffer size. * returns: amount of fields read or -1 on error. */ @@ -86,7 +87,7 @@ parseline(char **line, size_t *size, char **fields, return -1; for(prev = *line, i = 0; - (s = strchr(prev, separator)) && i <= maxfields; + (s = strchr(prev, separator)) && i < maxfields - 1; i++) { *s = '\0'; fields[i] = prev; |