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

List:       busybox
Subject:    editors/patch.c is broken
From:       "Nguyen Thai Ngoc Duy" <pclouds () gmail ! com>
Date:       2007-07-31 19:30:45
Message-ID: fcaeb9bf0707311230v1aaff203n60f67a9e3d958a1d () mail ! gmail ! com
[Download RAW message or body]

src/dest file names are read by xmalloc_fgets which include trailing
\n characters. Therefore patch either reads from wrong source file or
write to wrong destination file. The attached patch should fix it.
I'm not sure about the rest of xmalloc_fgets used in patch, though.
-- 
Duy

["0001-patch-cannot-open-files-because-of-trailing-n.patch" (text/x-patch)]

From d999a538d160cdc79e55f64f500cfc7d75d36cf1 Mon Sep 17 00:00:00 2001
From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date: Tue, 31 Jul 2007 10:20:41 -0400
Subject: [PATCH] patch cannot open files because of trailing \n

need to submit upstream
---
 box/editors/patch.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/box/editors/patch.c b/box/editors/patch.c
index f65bbf4..5f7f7d0 100644
--- a/box/editors/patch.c
+++ b/box/editors/patch.c
@@ -96,7 +96,7 @@ int patch_main(int argc, char **argv)
 		ret = 0;
 	}
 
-	patch_line = xmalloc_fgets(patch_file);
+	patch_line = xmalloc_getline(patch_file);
 	while (patch_line) {
 		FILE *src_stream;
 		FILE *dst_stream;
@@ -115,7 +115,7 @@ int patch_main(int argc, char **argv)
 		 */
 		while (patch_line && strncmp(patch_line, "--- ", 4) != 0) {
 			free(patch_line);
-			patch_line = xmalloc_fgets(patch_file);
+			patch_line = xmalloc_getline(patch_file);
 		}
 		/* FIXME: patch_line NULL check?? */
 
@@ -123,7 +123,7 @@ int patch_main(int argc, char **argv)
 		original_filename = extract_filename(patch_line, patch_level);
 		free(patch_line);
 
-		patch_line = xmalloc_fgets(patch_file);
+		patch_line = xmalloc_getline(patch_file);
 		/* FIXME: NULL check?? */
 		if (strncmp(patch_line, "+++ ", 4) != 0) {
 			ret = 2;
-- 
1.5.0.7



_______________________________________________
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