Bug 11276 - remove(3) fails when unlink(2) returns `EPERM'
Summary: remove(3) fails when unlink(2) returns `EPERM'
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-12 09:50 UTC by Ludovic Courtès
Modified: 2014-06-30 18:48 UTC (History)
2 users (show)

See Also:
Host: i386-unknown-gnu0.3
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Courtès 2010-02-12 09:50:59 UTC
Currently sysdeps/posix/remove.c reads this:

#v+
int
remove (file)
     const char *file;
{
  /* First try to unlink since this is more frequently the necessary action. */
  if (__unlink (file) != 0
      /* If it is indeed a directory...  */
      && (errno != EISDIR
	  /* ...try to remove it.  */
	  || __rmdir (file) != 0))
    /* Cannot remove the object for whatever reason.  */
    return -1;

  return 0;
}
#v-

However, POSIX says unlink(2) returns `EPERM' when PATH is a directory. `EISDIR'
is Linux-specific and the "Rationale" section at
http://www.opengroup.org/onlinepubs/9699919799/functions/unlink.html says that
"[a]pplications written for portability to both POSIX.1-2008 and the LSB should
be prepared to handle either error code."

Currently remove(3) fails on GNU/Hurd [0] and GNU/kFreeBSD [1] because of this.
 Thus it should be changed to handle both `EPERM' and `EISDIR'.

[0] https://savannah.gnu.org/bugs/?28859
[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=557248
Comment 1 Ulrich Drepper 2010-04-04 09:09:13 UTC
Changed in git.