From a7876db304a29c330eb1ad584933176939287fc8 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 14 Sep 2010 04:17:24 +0200 Subject: Fix compressed binaries execution * exec/exec.c (check_gzip.zipread): Add `n' to `zipread_pos' to fix infinite loop. (check_bzip2.zipread): Likewise. (check_gzip): Set `file_data' and `file_size' fields after calling `finish' instead of before. (check_bzip2): Likewise. --- exec/exec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'exec/exec.c') diff --git a/exec/exec.c b/exec/exec.c index 9273a4cb..d8765003 100644 --- a/exec/exec.c +++ b/exec/exec.c @@ -1151,6 +1151,7 @@ check_gzip (struct execdata *earg) } n = MIN (maxread, map_buffer (e) + map_fsize (e) - contents); memcpy (buf, contents, n); /* XXX/fault */ + zipread_pos += n; return n; } void zipwrite (const char *buf, size_t nwrite) @@ -1210,8 +1211,6 @@ check_gzip (struct execdata *earg) /* The output is complete. Clean up the stream and store its resultant buffer and size in the execdata as the file contents. */ fclose (zipout); - e->file_data = zipdata; - e->file_size = zipdatasz; /* Clean up the old exec file stream's state. Now that we have the contents all in memory (in E->file_data), @@ -1219,6 +1218,8 @@ check_gzip (struct execdata *earg) finish (e, 0); /* Prepare the stream state to use the file contents already in memory. */ + e->file_data = zipdata; + e->file_size = zipdatasz; prepare_in_memory (e); } #endif @@ -1257,6 +1258,7 @@ check_bzip2 (struct execdata *earg) } n = MIN (maxread, map_buffer (e) + map_fsize (e) - contents); memcpy (buf, contents, n); /* XXX/fault */ + zipread_pos += n; return n; } void zipwrite (const char *buf, size_t nwrite) @@ -1305,8 +1307,6 @@ check_bzip2 (struct execdata *earg) /* The output is complete. Clean up the stream and store its resultant buffer and size in the execdata as the file contents. */ fclose (zipout); - e->file_data = zipdata; - e->file_size = zipdatasz; /* Clean up the old exec file stream's state. Now that we have the contents all in memory (in E->file_data), @@ -1314,6 +1314,8 @@ check_bzip2 (struct execdata *earg) finish (e, 0); /* Prepare the stream state to use the file contents already in memory. */ + e->file_data = zipdata; + e->file_size = zipdatasz; prepare_in_memory (e); } #endif -- cgit v1.2.3