Date: Fri, 23 Sep 2005 11:02:12 -0700 From: Doug Barton <dougb@FreeBSD.org> To: freebsd-hackers@FreeBSD.org Subject: Fixing an error condition for 'rm -P' Message-ID: <43344324.10202@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------090401060105060209040000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I have rm aliased to '/bin/rm -P', mostly for fun, but I like the idea. There is an oddity however when you use the -P flag, and the file is not writable. The check() function in rm.c specifically ignores this condition, and lets the thing fail later in the program. I think this is bad on an objective level, but it definitely leads to annoying problems for the user when you hit this condition. I therefore propose the attached patch. Doug -- This .signature sanitized for your protection --------------090401060105060209040000 Content-Type: text/plain; name="rm-P-errx.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rm-P-errx.diff" Index: rm.c =================================================================== RCS file: /usr/local/ncvs/src/bin/rm/rm.c,v retrieving revision 1.52 diff -u -r1.52 rm.c --- rm.c 13 Nov 2004 04:07:01 -0000 1.52 +++ rm.c 23 Sep 2005 08:29:38 -0000 @@ -452,11 +452,8 @@ * talking to a terminal, ask. Symbolic links are excluded * because their permissions are meaningless. Check stdin_ok * first because we may not have stat'ed the file. - * Also skip this check if the -P option was specified because - * we will not be able to overwrite file contents and will - * barf later. */ - if (!stdin_ok || S_ISLNK(sp->st_mode) || Pflag || + if (!stdin_ok || S_ISLNK(sp->st_mode) || (!access(name, W_OK) && !(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) && (!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !uid))) @@ -464,6 +461,9 @@ strmode(sp->st_mode, modep); if ((flagsp = fflagstostr(sp->st_flags)) == NULL) err(1, "fflagstostr"); + if (Pflag) + errx(1, + "-P was specified, but %s is not writable", path); (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ", modep + 1, modep[9] == ' ' ? "" : " ", user_from_uid(sp->st_uid, 0), --------------090401060105060209040000--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?43344324.10202>