From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10128 invoked by alias); 19 Nov 2010 16:34:10 -0000 Received: (qmail 10039 invoked by uid 22791); 19 Nov 2010 16:34:09 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 19 Nov 2010 16:34:05 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAJGY4o2029599 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Nov 2010 11:34:04 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAJGY3Sf015437 for ; Fri, 19 Nov 2010 11:34:03 -0500 From: Phil Muldoon To: gdb-patches@sourceware.org Subject: [patch] Fix fileio.exp failuew when run as root user. Reply-to: pmuldoon@redhat.com X-URL: http://www.redhat.com Date: Fri, 19 Nov 2010 16:34:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-11/txt/msg00259.txt.bz2 This patch has been carried in the Fedora RPM since 6.8. We are submitting it for inclusion upstream. gdb.base/fileio.exp|c fail when this test is executed as a root. This test fixes that. 2010-11-19 Jan Kratochvil * gdb.base/fileio.c (ROOTSUBDIR): New macro. (main): CHDIR into ROOTSUBDIR. CHOWN ROOTSUBDIR and CHDIR into ROOTSUBDIR if we are being run as root. * gdb.base/fileio.exp: Change the startup and finish cleanup. Change the test file reference to be into the `fileio.dir' directory. -- diff --git a/gdb/testsuite/gdb.base/fileio.c b/gdb/testsuite/gdb.base/fileio.c index 329522f..7c69d4c 100644 --- a/gdb/testsuite/gdb.base/fileio.c +++ b/gdb/testsuite/gdb.base/fileio.c @@ -58,6 +58,8 @@ system (const char * string); 1) Invalid string/command. - returns 127. */ static const char *strerrno (int err); +#define ROOTSUBDIR "fileio.dir" + #define FILENAME "foo.fileio.test" #define RENAMED "bar.fileio.test" #define NONEXISTANT "nofoo.fileio.test" @@ -542,6 +544,37 @@ strerrno (int err) int main () { + /* ROOTSUBDIR is already prepared by fileio.exp. We use it for easy cleanup + (by fileio.exp) if we are run by multiple users in the same directory. */ + + if (chdir (ROOTSUBDIR) != 0) + { + printf ("chdir " ROOTSUBDIR ": %s\n", strerror (errno)); + exit (1); + } + + /* These tests + Open for write but no write permission returns EACCES + Unlinking a file in a directory w/o write access returns EACCES + fail if we are being run as root - drop the privileges here. */ + + if (geteuid () == 0) + { + uid_t uid = 99; + + if (chown (".", uid, uid) != 0) + { + printf ("chown %d.%d " ROOTSUBDIR ": %s\n", (int) uid, (int) uid, + strerror (errno)); + exit (1); + } + if (setuid (uid) || geteuid () == 0) + { + printf ("setuid %d: %s\n", (int) uid, strerror (errno)); + exit (1); + } + } + /* Don't change the order of the calls. They partly depend on each other */ test_open (); test_write (); diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp index d6242d0..ddb853c 100644 --- a/gdb/testsuite/gdb.base/fileio.exp +++ b/gdb/testsuite/gdb.base/fileio.exp @@ -42,8 +42,8 @@ if [get_compiler_info ${binfile}] { return -1; } -remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test} -remote_exec build {sh -xc rm\ -rf\ *.fileio.test} +remote_exec build {sh -xc rm\ -rf\ fileio.dir} +remote_exec build {sh -xc mkdir\ -m777\ fileio.dir} set oldtimeout $timeout set timeout [expr "$timeout + 60"] @@ -85,7 +85,7 @@ gdb_test continue \ gdb_test "continue" ".*" "" -catch "system \"chmod -f -w nowrt.fileio.test\"" +catch "system \"chmod -f -w fileio.dir/nowrt.fileio.test\"" gdb_test continue \ "Continuing\\..*open 5:.*EACCES$stop_msg" \ @@ -250,8 +250,8 @@ gdb_test continue \ send_gdb "quit\n" send_gdb "y\n" -remote_exec build {sh -xc test\ -r\ dir2.fileio.test\ &&\ chmod\ -f\ +w\ dir2.fileio.test} -remote_exec build {sh -xc rm\ -rf\ *.fileio.test} +remote_exec build {sh -xc test\ -r\ fileio.dir/dir2.fileio.test\ &&\ chmod\ -f\ +w\ fileio.dir/dir2.fileio.test} +remote_exec build {sh -xc rm\ -rf\ fileio.dir} set timeout $oldtimeout return 0