summaryrefslogtreecommitdiff
path: root/user/readstat/use-after-free.patch
blob: 70ea38ffd15647b1aa1b567143ab55eeae706379 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
From 718d49155e327471ed9bf4a8c157f849f285b46c Mon Sep 17 00:00:00 2001
From: Stefan Gerlach <stefan.gerlach@uni-konstanz.de>
Date: Wed, 20 Sep 2023 15:18:07 +0200
Subject: [PATCH] Fix use after free (#298)

---
 src/bin/readstat.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/bin/readstat.c b/src/bin/readstat.c
index 48b8fdd..e3fbbd1 100644
--- a/src/bin/readstat.c
+++ b/src/bin/readstat.c
@@ -397,8 +397,6 @@ static int convert_file(const char *input_filename, const char *catalog_filename
         module->finish(rs_ctx->module_ctx);
     }
 
-    free(rs_ctx);
-
     if (error != READSTAT_OK) {
         if (file_exists) {
             fprintf(stderr, "Error opening %s: File exists (Use -f to overwrite)\n", output_filename);
@@ -406,9 +404,14 @@ static int convert_file(const char *input_filename, const char *catalog_filename
             fprintf(stderr, "Error processing %s: %s\n", rs_ctx->error_filename, readstat_error_message(error));
             unlink(output_filename);
         }
+
+	free(rs_ctx);
+
         return 1;
     }
 
+    free(rs_ctx);
+
     return 0;
 }