Browse code

bb11023 - Wrong declaration of function destroy_ctx to cause undefined behavior

Shawn Webb authored on 2014/06/02 21:54:43
Showing 3 changed files
... ...
@@ -1530,12 +1530,12 @@ static int vbadump(const struct optstruct *opts)
1530 1530
 	return -1;
1531 1531
     }
1532 1532
     if(cli_ole2_extract(dir, ctx, &vba)) {
1533
-	destroy_ctx(ctx);
1533
+	destroy_ctx(-1, ctx);
1534 1534
 	cli_rmdirs(dir);
1535 1535
         free(dir);
1536 1536
         return -1;
1537 1537
     }
1538
-    destroy_ctx(ctx);
1538
+    destroy_ctx(-1, ctx);
1539 1539
     if (vba) 
1540 1540
       sigtool_vba_scandir(dir, hex_output, vba);
1541 1541
     cli_rmdirs(dir);
... ...
@@ -93,7 +93,8 @@ cli_ctx *convenience_ctx(int fd) {
93 93
 
94 94
 void destroy_ctx(int desc, cli_ctx *ctx) {
95 95
     funmap(*(ctx->fmap));
96
-    close(desc);
96
+    if (desc >= 0)
97
+        close(desc);
97 98
     free(ctx->fmap);
98 99
     cl_engine_free((struct cl_engine *)ctx->engine);
99 100
     free(ctx);
... ...
@@ -25,6 +25,6 @@
25 25
 
26 26
 int sigtool_vba_scandir(const char *dirname, int hex_output, struct uniq *U);
27 27
 cli_ctx *convenience_ctx(int fd);
28
-void destroy_ctx(cli_ctx *ctx);
28
+void destroy_ctx(int desc, cli_ctx *ctx);
29 29
 
30 30
 #endif