aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 14:23:29 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 14:23:29 +0000
commit22dca23d52c836e40c79cb4042b867fdc06f6ca3 (patch)
treea9f7e6c318e749875288358c963d53c25fab681a
parent314908da9e156e3100275598dde6848da038d65d (diff)
downloadbusybox-w32-22dca23d52c836e40c79cb4042b867fdc06f6ca3.tar.gz
busybox-w32-22dca23d52c836e40c79cb4042b867fdc06f6ca3.tar.bz2
busybox-w32-22dca23d52c836e40c79cb4042b867fdc06f6ca3.zip
archival: added O_TRUNC so that when we overwrite files on unpack,
we truncate them. Also spotted & fixed hard to trigger bug with extension handling.
-rw-r--r--archival/bunzip2.c13
-rw-r--r--archival/gunzip.c3
-rw-r--r--archival/uncompress.c3
-rw-r--r--archival/unlzma.c11
-rw-r--r--archival/unzip.c2
5 files changed, 19 insertions, 13 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index a970aeb20..9810e0290 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -41,17 +41,20 @@ int bunzip2_main(int argc, char **argv)
41 41
42 if (filename) { 42 if (filename) {
43 struct stat stat_buf; 43 struct stat stat_buf;
44 char *extension=filename+strlen(filename)-4; 44 /* extension = filename+strlen(filename)-4 is buggy:
45 if (strcmp(extension, ".bz2") != 0) { 45 * strlen may be less than 4 */
46 char *extension = strrchr(filename, '.');
47 if (!extension || strcmp(extension, ".bz2") != 0) {
46 bb_error_msg_and_die("Invalid extension"); 48 bb_error_msg_and_die("Invalid extension");
47 } 49 }
48 xstat(filename, &stat_buf); 50 xstat(filename, &stat_buf);
49 *extension=0; 51 *extension = '\0';
50 dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); 52 dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
53 stat_buf.st_mode);
51 } else dst_fd = STDOUT_FILENO; 54 } else dst_fd = STDOUT_FILENO;
52 status = uncompressStream(src_fd, dst_fd); 55 status = uncompressStream(src_fd, dst_fd);
53 if(filename) { 56 if(filename) {
54 if (!status) filename[strlen(filename)]='.'; 57 if (!status) filename[strlen(filename)] = '.';
55 if (unlink(filename) < 0) { 58 if (unlink(filename) < 0) {
56 bb_error_msg_and_die("Couldn't remove %s", filename); 59 bb_error_msg_and_die("Couldn't remove %s", filename);
57 } 60 }
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 3a1d1cb61..7be94e1b8 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -98,7 +98,8 @@ int gunzip_main(int argc, char **argv)
98 } 98 }
99 99
100 /* Open output file (with correct permissions) */ 100 /* Open output file (with correct permissions) */
101 dst_fd = xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode); 101 dst_fd = xopen3(new_path, O_WRONLY | O_CREAT | O_TRUNC,
102 stat_buf.st_mode);
102 103
103 /* If unzip succeeds remove the old file */ 104 /* If unzip succeeds remove the old file */
104 delete_path = old_path; 105 delete_path = old_path;
diff --git a/archival/uncompress.c b/archival/uncompress.c
index ca775c787..8c466ebdf 100644
--- a/archival/uncompress.c
+++ b/archival/uncompress.c
@@ -55,7 +55,8 @@ int uncompress_main(int argc, char **argv)
55 55
56 /* Open output file */ 56 /* Open output file */
57 xstat(compressed_file, &stat_buf); 57 xstat(compressed_file, &stat_buf);
58 dst_fd = xopen3(uncompressed_file, O_WRONLY | O_CREAT, 58 dst_fd = xopen3(uncompressed_file,
59 O_WRONLY | O_CREAT | O_TRUNC,
59 stat_buf.st_mode); 60 stat_buf.st_mode);
60 61
61 /* If unzip succeeds remove the old file */ 62 /* If unzip succeeds remove the old file */
diff --git a/archival/unlzma.c b/archival/unlzma.c
index fbd207ca1..00acea6e0 100644
--- a/archival/unlzma.c
+++ b/archival/unlzma.c
@@ -37,14 +37,15 @@ int unlzma_main(int argc, char **argv)
37 37
38 if (filename) { 38 if (filename) {
39 struct stat stat_buf; 39 struct stat stat_buf;
40 char *extension = filename + strlen(filename) - 5; 40 /* bug: char *extension = filename + strlen(filename) - 5; */
41 41 char *extension = strrchr(filename, '.');
42 if (strcmp(extension, ".lzma") != 0) { 42 if (!extension || strcmp(extension, ".lzma") != 0) {
43 bb_error_msg_and_die("Invalid extension"); 43 bb_error_msg_and_die("Invalid extension");
44 } 44 }
45 xstat(filename, &stat_buf); 45 xstat(filename, &stat_buf);
46 *extension = 0; 46 *extension = '\0';
47 dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); 47 dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
48 stat_buf.st_mode);
48 } else 49 } else
49 dst_fd = STDOUT_FILENO; 50 dst_fd = STDOUT_FILENO;
50 status = unlzma(src_fd, dst_fd); 51 status = unlzma(src_fd, dst_fd);
diff --git a/archival/unzip.c b/archival/unzip.c
index 6dd1d3597..709ebf81a 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -333,7 +333,7 @@ int unzip_main(int argc, char **argv)
333 overwrite = o_always; 333 overwrite = o_always;
334 case 'y': /* Open file and fall into unzip */ 334 case 'y': /* Open file and fall into unzip */
335 unzip_create_leading_dirs(dst_fn); 335 unzip_create_leading_dirs(dst_fn);
336 dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT, 0777); 336 dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, 0777);
337 case -1: /* Unzip */ 337 case -1: /* Unzip */
338 if (verbosity == v_normal) { 338 if (verbosity == v_normal) {
339 printf(" inflating: %s\n", dst_fn); 339 printf(" inflating: %s\n", dst_fn);