From 0d1dd2497f0a1ed5a3c82d73e3fbc168bb61e13a Mon Sep 17 00:00:00 2001 From: nico Date: Fri, 24 Aug 2001 11:36:40 +0000 Subject: [PATCH] Make sure we don't crash while trying to parse a command line argument as being a property list git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10782 72102866-910b-0410-8b05-ffd578937521 --- Source/NSUserDefaults.m | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index a3af0bdb9..409e98fe4 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -1155,11 +1155,34 @@ static NSString *pathForUser(NSString *user) } else { // Real parameter - val = [val propertyList]; - [argDict setObject: val forKey: key]; + /* Parsing the argument as a property list is very + delicate. We *MUST NOT* crash here just because a + strange parameter (such as `(load "test.scm")`) is + passed, otherwise the whole library is useless in a + foreign environment. */ + NSObject *plist_val; + + NS_DURING + { + plist_val = [val propertyList]; + } + NS_HANDLER + { + plist_val = val; + } + NS_ENDHANDLER + + /* Make sure we don't crash being caught adding nil to + a dictionary. */ + if (plist_val == nil) + { + plist_val = val; + } + + [argDict setObject: plist_val forKey: key]; if (old != nil) { - [argDict setObject: val forKey: old]; + [argDict setObject: plist_val forKey: old]; } } }