From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2871 invoked by alias); 25 Jul 2007 11:53:51 -0000 Received: (qmail 2858 invoked by uid 22791); 25 Jul 2007 11:53:50 -0000 X-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,FORGED_RCVD_HELO X-Spam-Check-By: sourceware.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (83.160.170.119) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 25 Jul 2007 11:53:48 +0000 Received: from dijkstra.wildebeest.org ([192.168.1.29]) by gnu.wildebeest.org with esmtp (Exim 4.43) id 1IDfTb-0005HQ-1Y; Wed, 25 Jul 2007 13:56:24 +0200 Subject: Re: frysk-sys/frysk bindir/ChangeLog proc/live/Cha ... From: Mark Wielaard To: frysk@sourceware.org Cc: cagney@sourceware.org In-Reply-To: <20070718191111.26695.qmail@sourceware.org> References: <20070718191111.26695.qmail@sourceware.org> Content-Type: text/plain Date: Wed, 25 Jul 2007 11:53:00 -0000 Message-Id: <1185364424.3597.18.camel@dijkstra.wildebeest.org> Mime-Version: 1.0 X-Mailer: Evolution 2.8.3 (2.8.3-2.fc6) Content-Transfer-Encoding: 7bit X-Spam-Score: -4.3 (----) X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q3/txt/msg00171.txt.bz2 Hi Andrew, On Wed, 2007-07-18 at 19:11 +0000, cagney@sourceware.org wrote: > 2007-07-18 Andrew Cagney > > * LinuxProc.java: Use frysk.sys.proc.Exe.get. Validate the > returned string, returning NULL when a problem. > /** > * A Linux Proc tracked using PTRACE. > @@ -199,19 +199,32 @@ > } > /** > * Get the Executable. > - */ > - protected String sendrecExe () > - { > - String exeString = "/proc/" + getPid() + "/exe"; > - try > - { > - exeString = new File(exeString).getCanonicalPath(); > - } > - catch (IOException ioe) > - { > - // Just return exeString. No permission or process died. > - } > - return exeString; > + * > + * XXX: This is racy - it can miss file renames. The alternative > + * would be to have two methods; one returning a file descriptor > + * and a second returning the exe as it should be (but possibly > + * isn't :-). Better yet have utrace handle it :-) > + */ > + protected String sendrecExe () { > + String exe = Exe.get(getPid()); > + // Linux's /proc/$$/exe can get screwed up in several ways. > + // Detect each here and return null. > + if (exe.endsWith(" (deleted)")) > + // Assume (possibly incorrectly) that a trailing > + // "(deleted)" always indicates a deleted file. > + return null; > + if (exe.indexOf((char)0) >= 0) > + // Assume that an EXE that has somehow ended up with an > + // embedded NUL character is invalid. This happens when > + // the kernel screws up "mv a-really-long-file $exe" > + // leaving the updated EXE string with something like > + // "$exeally-long-file (deleted)". > + return null; > + if (new File(exe).exists()) > + // Final sanity check; the above two should have covered > + // all possible cases. But one never knows. > + return exe; > + return null; > } This break FryskGui which isn't prepared to handle null from Proc.get(). It is probably a good idea to make Proc.get() return a File object that the user can then inspect themselves (you won't get rid of the race anyway unless you explicitly open the file and return that as result, but that is probably not what you want here), then you can also easily find all users of this method so you can inspect whether or not they handle the new return value correctly. 2007-07-18 Andrew Cagney * cni/Exe.cxx (get): Allow space for "(deleted)"). If you do make getExe() return File, then you can also just use the standard File.getCanonicalFile() method, which will do all sanity checking already in proc.Exe so we don't need a special case cni implementation for it and doesn't depend on fixed buffer lengths. Cheers, Mark