From c90352008b22819ff903982c96d78bca108a06c4 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 21 Jul 2021 12:44:53 -0700 Subject: [PATCH] core/csv-import: don't do pointer math after realloc try_to_xslt_open_csv() re-allocates the memory passed in (not really great as far as design goes, maybe something that should be reimplemented). Doing pointer arithmatic with the returned base pointer results in garbage, unless one gets super lucky and the realloc manages to not move the memory. It's a wonder this ever worked. Signed-off-by: Dirk Hohndel --- core/import-csv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/import-csv.c b/core/import-csv.c index f24c5ec0b..34ac1348b 100644 --- a/core/import-csv.c +++ b/core/import-csv.c @@ -245,6 +245,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str return -1; } mem_csv.size = ptr - (char*)mem_csv.buffer; + end_ptr += ptr - (char *)mem_csv.buffer; iter = parse_dan_new_line(ptr + 1, NL); if (iter && strncmp(iter, "ZDT", 3) == 0) { @@ -268,7 +269,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str return -1; ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, devices, filter_presets, params); - end_ptr += ptr - (char *)mem_csv.buffer; + free(mem_csv.buffer); }