[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] fix mode setting of unpacked files for
From:       Denis Vlasenko <vda () ilport ! com ! ua>
Date:       2006-04-26 11:19:26
Message-ID: 200604261419.27015.vda () ilport ! com ! ua
[Download RAW message or body]

On Wednesday 26 April 2006 13:14, Bernhard Fischer wrote:
> On Wed, Apr 26, 2006 at 12:43:12PM +0300, Denis Vlasenko wrote:
> >busybox unlzma busybox.tar.lzma
> >
> >is producing busybox.tar with mode 0777! This patch fixes it.
> >
> >Also fixes same bug in bunzip2 and fixes racy mode setting in gunzip.
> >
> >Please apply
> 
> I'll leave this for someone else to review.

Well, I submitted it before, looks like it fell through
the cracks. It's small, not *that* much to review there.

> I see no good reason why we 
> shouldn't be using xstat there, fwiw.

Updated patch is attached.
--
vda

["unlzma_mode_fix_v4.patch" (text/x-diff)]

diff -urpN busybox.org1/archival/bunzip2.c busybox.unlzma_mode_fix/archival/bunzip2.c
--- busybox.org1/archival/bunzip2.c	Tue Apr 18 13:59:12 2006
+++ busybox.unlzma_mode_fix/archival/bunzip2.c	Wed Apr 26 14:09:54 2006
@@ -41,19 +41,22 @@ int bunzip2_main(int argc, char **argv)
 
 	/* Check that the input is sane.  */
 	if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) {
-		bb_error_msg_and_die("compressed data not read from terminal.  Use -f to force it.");
+		bb_error_msg_and_die("Compressed data not read from terminal.  Use -f to force it.");
 	}
 
 	if (filename) {
-		char *extension=filename+strlen(filename)-4;
+		struct stat stat_buf;
+		char *extension = filename+strlen(filename)-4;
 		if (strcmp(extension, ".bz2") != 0) {
 			bb_error_msg_and_die("Invalid extension");
 		}
-		*extension=0;
+		xstat(filename, &stat_buf);
+		*extension = 0;
 		dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT);
+		fchmod(dst_fd, stat_buf.st_mode);
 	} else dst_fd = STDOUT_FILENO;
 	status = uncompressStream(src_fd, dst_fd);
-	if(filename) {
+	if (filename) {
 		if (!status) filename[strlen(filename)]='.';
 		if (unlink(filename) < 0) {
 			bb_error_msg_and_die("Couldn't remove %s", filename);
diff -urpN busybox.org1/archival/gunzip.c busybox.unlzma_mode_fix/archival/gunzip.c
--- busybox.org1/archival/gunzip.c	Mon Mar 13 22:24:01 2006
+++ busybox.unlzma_mode_fix/archival/gunzip.c	Wed Apr 26 14:08:21 2006
@@ -141,7 +141,7 @@ int gunzip_main(int argc, char **argv)
 			dst_fd = bb_xopen(new_path, O_WRONLY | O_CREAT);
 
 			/* Set permissions on the file */
-			chmod(new_path, stat_buf.st_mode);
+			fchmod(dst_fd, stat_buf.st_mode);
 
 			/* If unzip succeeds remove the old file */
 			delete_path = old_path;
diff -urpN busybox.org1/archival/unlzma.c busybox.unlzma_mode_fix/archival/unlzma.c
--- busybox.org1/archival/unlzma.c	Thu Feb  9 10:41:51 2006
+++ busybox.unlzma_mode_fix/archival/unlzma.c	Wed Apr 26 14:08:50 2006
@@ -41,13 +41,16 @@ int unlzma_main(int argc, char **argv)
 		filename = 0;
 
 	if (filename) {
+		struct stat stat_buf;
 		char *extension = filename + strlen(filename) - 5;
 
 		if (strcmp(extension, ".lzma") != 0) {
 			bb_error_msg_and_die("Invalid extension");
 		}
+		xstat(filename, &stat_buf);
 		*extension = 0;
 		dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT);
+		fchmod(dst_fd, stat_buf.st_mode);
 	} else
 		dst_fd = STDOUT_FILENO;
 	status = unlzma(src_fd, dst_fd);


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic