From 9ebc2a17515af7f7196362c9f7373fcea36c7835 Mon Sep 17 00:00:00 2001 From: Tharre Date: Tue, 2 Aug 2016 11:05:32 +0200 Subject: Fix overflow error when there are too many fields --- src/DSV.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/DSV.c') diff --git a/src/DSV.c b/src/DSV.c index 91cc7ee..1a46007 100644 --- a/src/DSV.c +++ b/src/DSV.c @@ -117,17 +117,18 @@ int dsv_parse_next_line(struct dsv_ctx *context, const char *src, size_t len) { break; } + if (i >= context->fields_count) { + debug("DSV: too many fields\n"); + context->status = E_TOO_MANY_FIELDS; + goto error; + } + char *buf = xmalloc(size+1); decode_string(buf, start, size+1); context->fields[i] = buf; start += size + 1; ++i; - if (i > context->fields_count) { - debug("DSV: too many fields\n"); - context->status = E_TOO_MANY_FIELDS; - goto error; - } } if (i+1 < context->fields_count) { -- cgit v1.2.3-70-g09d2