From 95792f701c5797ae07f5784f1b5cc989355be7ff Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 14 Aug 2007 13:26:47 +0000 Subject: [PATCH] fix cross-device links with --follow-symlinks 2007-08-14 Paolo Bonzini * sed/execute.c (open_next_file): Follow symlink here... (closedown): ... not here. git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-96 --- ChangeLog | 5 +++++ NEWS | 6 ++++++ sed/execute.c | 16 ++++++++-------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a7f719..e908451 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-08-14 Paolo Bonzini + + * sed/execute.c (open_next_file): Follow symlink here... + (closedown): ... not here. + 2007-06-29 Paolo Bonzini * sed/mbcs.c: Upgrade to GPLv3. diff --git a/NEWS b/NEWS index 3da2b20..952920f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +Sed 4.1e + +* fixed --follow-symlinks to avoid attempting the creation of cross-device +links. + +---------------------------------------------------------------------------- Sed 4.1d (final release candidate for sed 4.2) * fixed bug in 'i\' giving a segmentation violation if given alone. diff --git a/sed/execute.c b/sed/execute.c index e33c7f8..490d3b7 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -707,16 +707,20 @@ open_next_file(name, input) if (in_place_extension) { int input_fd, output_fd; - char *tmpdir = ck_strdup(name), *p; + char *tmpdir, *p; struct stat st; + if (follow_symlinks) + input->in_file_name = follow_symlink (name); + else + input->in_file_name = name; + /* get the base name */ + tmpdir = ck_strdup(input->in_file_name); if (p = strrchr(tmpdir, '/')) *(p + 1) = 0; else strcpy(tmpdir, "."); - - input->in_file_name = name; if (isatty (fileno (input->fp))) panic(_("couldn't edit %s: is a terminal"), input->in_file_name); @@ -762,11 +766,7 @@ closedown(input) const char *target_name; ck_fclose (output_file.fp); - if (follow_symlinks) - target_name = follow_symlink (input->in_file_name); - else - target_name = input->in_file_name; - + target_name = input->in_file_name; if (strcmp(in_place_extension, "*") != 0) { char *backup_file_name = get_backup_file_name(target_name);