From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#12632: file permissions checking mishandled when setuid Date: Mon, 22 Oct 2012 19:19:53 +0200 Message-ID: <83ipa2ctl2.fsf@gnu.org> References: <5078CAB6.7020509@cs.ucla.edu> <83fw5h5yo6.fsf@gnu.org> <507B010F.20105@cs.ucla.edu> <831uh06gqd.fsf@gnu.org> <507B15B0.2040802@cs.ucla.edu> <83txtw4xmk.fsf@gnu.org> <507B2354.3030408@cs.ucla.edu> <83sj9g4vy7.fsf@gnu.org> <507BAA6C.2000601@cs.ucla.edu> <83lif74p78.fsf@gnu.org> <507C823D.40304@cs.ucla.edu> <83d30j3wqg.fsf@gnu.org> <507CF802.6000305@cs.ucla.edu> <83a9vm4bmv.fsf@gnu.org> <50818763.80501@cs.ucla.edu> <83wqymz4me.fsf@gnu.org> <5081A1DF.9000009@cs.ucla.edu> <5081ABD6.9060002@cs.ucla.edu> <23r4osd2f9.fsf@fencepost.gnu.org> <50836366.6080600@cs.ucla.edu> <5084E1B2.2020105@cs.ucla.edu> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1350926433 21045 80.91.229.3 (22 Oct 2012 17:20:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 22 Oct 2012 17:20:33 +0000 (UTC) Cc: 12632@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 22 19:20:40 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TQLg7-0002mt-Nc for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Oct 2012 19:20:39 +0200 Original-Received: from localhost ([::1]:34408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQLfy-00030c-G3 for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Oct 2012 13:20:30 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQLfq-0002yJ-CH for bug-gnu-emacs@gnu.org; Mon, 22 Oct 2012 13:20:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TQLfj-0003l1-81 for bug-gnu-emacs@gnu.org; Mon, 22 Oct 2012 13:20:20 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQLfj-0003kd-4V for bug-gnu-emacs@gnu.org; Mon, 22 Oct 2012 13:20:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TQLhR-0000Ib-QW for bug-gnu-emacs@gnu.org; Mon, 22 Oct 2012 13:22:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Oct 2012 17:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12632 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: security patch Original-Received: via spool by 12632-submit@debbugs.gnu.org id=B12632.13509265151132 (code B ref 12632); Mon, 22 Oct 2012 17:22:01 +0000 Original-Received: (at 12632) by debbugs.gnu.org; 22 Oct 2012 17:21:55 +0000 Original-Received: from localhost ([127.0.0.1]:56158 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TQLhK-0000IC-In for submit@debbugs.gnu.org; Mon, 22 Oct 2012 13:21:54 -0400 Original-Received: from mtaout23.012.net.il ([80.179.55.175]:51896) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TQLhH-0000Hs-IP for 12632@debbugs.gnu.org; Mon, 22 Oct 2012 13:21:52 -0400 Original-Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0MCB00K001ERJJ00@a-mtaout23.012.net.il> for 12632@debbugs.gnu.org; Mon, 22 Oct 2012 19:19:58 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MCB00KP31H9DFB0@a-mtaout23.012.net.il>; Mon, 22 Oct 2012 19:19:58 +0200 (IST) In-reply-to: <5084E1B2.2020105@cs.ucla.edu> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:65855 Archived-At: > Date: Sun, 21 Oct 2012 23:03:30 -0700 > From: Paul Eggert > Cc: 12632@debbugs.gnu.org > > +/* If FILE is a searchable directory or a symlink to a > + searchable directory, return true. Otherwise return > + false and set errno to an error number. */ > +bool > +file_accessible_directory_p (char const *file) > +{ > + ptrdiff_t len = strlen (file); > + bool ok; > + int faccessat_errno; > + USE_SAFE_ALLOCA; > + > + /* Normally a file F is an accessible directory if F/. is accessible. > + But omit the "/." if F is empty, as "" is not "/."; and omit the > + "/" if F ends in "/", as on some platforms "/" != "//". */ > + if (len) > + { > + char *buf = SAFE_ALLOCA (len + 3); > + memcpy (buf, file, len); > + strcpy (buf + len, "/." + (file[len - 1] == '/')); > + file = buf; > + } I think this should use IS_DIRECTORY_SEP instead of a literal '/'. > int > -sys_access (const char * path, int mode) > +sys_faccessat (int dirfd, const char * path, int mode, int flags) > { > DWORD attributes; > > + if (dirfd != AT_FDCWD) > + { > + errno = EINVAL; > + return -1; > + } My reading of Posix is that this should set errno to EBADF, not EINVAL. There's also a problem that sys_faccessat won't have a prototype, so compiling with -std=gnu99 will issue a warning, but that's not fatal, and we can add that later.