From 986a9e120d79f625cbd7b4c59ccfd479a6a149ec Mon Sep 17 00:00:00 2001 From: jakob Date: Thu, 11 May 2017 20:18:08 -0400 Subject: Reimplemented table dumping functions to operate on streams instead of file pointers --- src/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index d68961c..a3d8622 100644 --- a/src/main.c +++ b/src/main.c @@ -207,13 +207,20 @@ static void create_archive(char **paths, int argc, struct params p) { return; } - struct header *h = create_header(); - struct table_entry *root = calloc(sizeof(struct table_entry), 1), *cur; + struct header *h = create_header(); + struct table_entry *root = calloc(sizeof(struct table_entry), 1), *cur; + struct stream *table = stream_new(1); dump_header(fp, h); for (int i = 1; i < argc - p.vararg_index; i++) { cur = add_file(root, paths[i]); } - dump_table(fp, root); + dump_table(table, root); + /* FIXME: table->len steps the bounds of the table and leaks memory + which can potentially be a huge security risk. Either fix the + functionality that expands the stream in memory, or get a table + size. */ + stream_seek(table, 0, SEEK_SET); + stream_dump(fp, table, table->len); } -- cgit v1.3