gh0stisic / volatility

Automatically exported from code.google.com/p/volatility
0 stars 0 forks source link

Path does not exist errors could be handled more gracefully #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hey guys, 

Not a big deal, but to prevent lots of annoying emails from users in the 
future, maybe we could make these error messages more graceful?

$ python volatility.py -f nonexistant

Volatile Systems Volatility Framework 1.4_rc1
ERROR   : volatility.plugins.fileparam: The requested file doesn't exist
*** Failed to import volatility.plugins.fileparam (SystemExit: 1)
Traceback (most recent call last):
  File "volatility.py", line 126, in <module>
    main()
  File "volatility.py", line 90, in main
    config.parse_options(False)
  File "/Users/mike/Desktop/Volatility-1.4_r599/volatility/conf.py", line 225, in parse_options
    (opts, args) = self.optparser.parse_args()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1380, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/Users/mike/Desktop/Volatility-1.4_r599/volatility/conf.py", line 84, in _process_args
    return optparse.OptionParser._process_args(self, largs, rargs, values)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1424, in _process_args
    self._process_short_opts(rargs, values)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1531, in _process_short_opts
    option.process(opt, value, values, self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 774, in process
    self.action, self.dest, opt, value, values, parser)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 794, in take_action
    self.callback(self, opt, value, parser, *args, **kwargs)
  File "/Users/mike/Desktop/Volatility-1.4_r599/volatility/plugins/fileparam.py", line 33, in set_location
    if not os.path.exists(os.path.abspath(value)):
AttributeError: 'NoneType' object has no attribute 'path'

Original issue reported on code.google.com by michael.hale@gmail.com on 19 Jan 2011 at 3:03

GoogleCodeExporter commented 9 years ago
Hmmmm, so this is actually more interesting than it looks, because the error 
message is that NoneType has no attribute path in the line 
os.path.exists(os.path.abspath(value)).  So the problem isn't anything to do 
with the value.  Here's what happens (for those that are interested):

The plugins all get imported when required, and the fileparam config handler is 
a plugin (seemed reasonable at the time).  The fileparam config entry just 
takes whatever it's been given and turns it into a location parameter (and only 
overrides the location if it's not already set).

During the import the config option gets added, which I think causes a parse of 
the options handed in.  During this first run it detects the file doesn't exist 
and returns an "ERROR   : volatility.plugins.fileparam: The requested file 
doesn't exist", which is exactly what we wanted it to do.  Then it exits (as 
errors are supposed to do), but that's actually caught by the plugin importer!  
It shows us the failure (*** Failed to import volatility.plugins.fileparam 
(SystemExit: 1)) and then *doesn't save* the module it loaded, and carries on 
with the next plugin.  Already disaster is lurking...

Then another parse of the command line is requested somehow (actually there's 
several iterations of this, as can be seen by changing the error to a warning). 
 The callback function (which was loaded and copied into the config objects by 
the add_config call) gets called, but because the module it came from wasn't 
saved, all the imports are gone, so at this point os really is None!  Since 
we're no longer in the plugin importer's safety net of try/except, we get that 
big backtrace at the end.

Worse, this is one of the only cases where asking for a frame's module (as the 
debugger does to generate the right location) also returns None, so even adding 
an import os right in the function doesn't solve all the problems.

My chosen solution is to catch only Exceptions not BaseExceptions, which should 
allow system-exiting exceptions (such as SystemExit and KeyboardInterrupt, and 
possibly very bad ones like SystemError and MemoryError), through, which now 
means you don't have to Ctrl+C several times to get out of the plugin loading 
process either.  5:)

Original comment by mike.auty@gmail.com on 19 Jan 2011 at 11:52

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r600.

Original comment by mike.auty@gmail.com on 19 Jan 2011 at 11:53