public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: frysk@sourceware.org
Cc: cagney@sourceware.org
Subject: Re: frysk-sys/frysk bindir/ChangeLog proc/live/Cha ...
Date: Wed, 25 Jul 2007 11:53:00 -0000	[thread overview]
Message-ID: <1185364424.3597.18.camel@dijkstra.wildebeest.org> (raw)
In-Reply-To: <20070718191111.26695.qmail@sourceware.org>

Hi Andrew,

On Wed, 2007-07-18 at 19:11 +0000, cagney@sourceware.org wrote: 
> 	2007-07-18  Andrew Cagney  <cagney@redhat.com>
> 	
> 	* 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
> +	    // "$exe<NUL>ally-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  <cagney@redhat.com>
        
        * 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

       reply	other threads:[~2007-07-25 11:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070718191111.26695.qmail@sourceware.org>
2007-07-25 11:53 ` Mark Wielaard [this message]
2007-07-25 12:07   ` [patch] PickProcDialog vs Proc.getExe() Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1185364424.3597.18.camel@dijkstra.wildebeest.org \
    --to=mark@klomp.org \
    --cc=cagney@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).