GNU sed version 4.1, bug report
Jerry Lundström
prox at lunar-linux.org
Fri Jun 18 10:21:50 GMT 2004
Here is a patch for this.
/Jerry
Terry Chan wrote:
> sed-4.1 does NOT correctly perform chmod/chown when
> using the "sed -i" (edit in-place) feature.
>
> sed-4.0.9 does work.
>
> Simple test case:
>
> 1. touch this_is_an_empty_testfile
> 2. chmod 755 this_is_an_empty_testfile
> 3. chown 1000:1000 this_is_an_empty_testfile
> 4. sed -i "s/XX/x/" this_is_an_empty_testfile
> 5. ls -al this_is_an_empty_testfile
>
> And this will now show uid:gid of 0:0 and permissions of 600 for
> this_is_an_empty_testfile
>
> The problem is located in execute.c and the rewrite/changes in
> 4.1 vs 4.0.9.
>
> Specifically 4.1 execute.c line 675 still uses:
> fchmod (output_fd, st.st_mode);
>
> which is how sed-4.0.9 invokes the chmod as well. The problem is
> sed-4.1 does NOT use output_fd and now uses output_file.fp !!!!
> Similarly fchown usage is incorrect too as it still uses output_fd,
> but should be using output_file.fp.
>
> This bug in sed-4.1 clearly breaks the chmod and chown functionality that
> was working in sed-4.0.9.
-------------- next part --------------
--- sed-4.1.orig/sed/execute.c 2004-03-13 10:30:39.000000000 +0100
+++ sed-4.1/sed/execute.c 2004-06-18 12:15:32.000000000 +0200
@@ -672,11 +672,11 @@
fstat (fileno (input->fp), &st);
#ifdef HAVE_FCHMOD
- fchmod (output_fd, st.st_mode);
+ fchmod (fileno(output_file.fp), st.st_mode);
#endif
#ifdef HAVE_FCHOWN
- if (fchown (output_fd, st.st_uid, st.st_gid) == -1)
- fchown (output_fd, -1, st.st_gid);
+ if (fchown (fileno(output_file.fp), st.st_uid, st.st_gid) == -1)
+ fchown (fileno(output_file.fp), -1, st.st_gid);
#endif
output_file.missing_newline = false;
More information about the Lunar-dev
mailing list