summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-06-21 00:20:54 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-06-21 00:20:54 +0200
commitad7fdd4bf80b716ba438e59e66d27bba8e7acefb (patch)
treed89c4064c9982032b431cffea138a621237ae835
parent3a72c90c2f7348f3e989a8cbe557a99c6de0e026 (diff)
util: fix parseline crash
-rw-r--r--util.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/util.c b/util.c
index 8e26a87..d66117b 100644
--- a/util.c
+++ b/util.c
@@ -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;