From cc2c20a1deaf2bf312b6b9c7f5c91796dbc00033 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 9 Nov 2010 18:50:58 +0000 Subject: [PATCH] Bug 634334: Check that subdir argument really is one of the two cases we can handle. Wrap fileURLWithPath in @try/@catch so that we don't crash when it throws. Free bonus fix: If "en" is the language and doesn't have a translation, force the C locale. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19785 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome-utils/gnc-gnome-utils.c | 70 +++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/src/gnome-utils/gnc-gnome-utils.c b/src/gnome-utils/gnc-gnome-utils.c index 91d248c176..d44d0e7dd9 100644 --- a/src/gnome-utils/gnc-gnome-utils.c +++ b/src/gnome-utils/gnc-gnome-utils.c @@ -285,16 +285,19 @@ gnc_gnome_help (const char *dir, const char *detail) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *subdir = [NSString stringWithUTF8String: dir]; - NSString *help_dir = [NSString stringWithUTF8String: HF_HELP]; NSString *tag; NSURL *url = NULL; if (detail) tag = [NSString stringWithUTF8String: detail]; - else if ([subdir compare: help_dir] == NSOrderedSame) + else if ([subdir compare: @HF_HELP] == NSOrderedSame) tag = @"help"; - else + else if ([subdir compare: @HF_GUIDE] == NSOrderedSame) tag = @"index"; + else { + PWARN("gnc_gnome_help called with unknown subdirectory %s", dir); + return; + } if (![[NSBundle mainBundle] bundleIdentifier]) { /* If bundleIdentifier is NULL, then we're running from the @@ -345,31 +348,54 @@ gnc_gnome_help (const char *dir, const char *detail) fileExistsAtPath: completed_path isDirectory: &dir]) if (dir) { - url = [NSURL fileURLWithPath: - [[[completed_path - stringByAppendingPathComponent: subdir] - stringByAppendingPathComponent: tag] - stringByAppendingPathExtension: @"html"]]; + @try { + url = [NSURL fileURLWithPath: + [[[completed_path + stringByAppendingPathComponent: subdir] + stringByAppendingPathComponent: tag] + stringByAppendingPathExtension: @"html"]]; + } + @catch (NSException *e) { + PWARN("fileURLWithPath threw %s: %s", + [[e name] UTF8String], [[e reason] UTF8String]); + return; + } break; } + if ([this_lang compare:@"en"] == NSOrderedSame) + break; /* Special case, forces use of "C" locale */ + } + } + if (!url) { + @try { + url = [NSURL + fileURLWithPath: [[[[docs_dir + stringByAppendingPathComponent: @"C"] + stringByAppendingPathComponent: subdir] + stringByAppendingPathComponent: tag] + stringByAppendingPathExtension: @"html"]]; + } + @catch (NSException *e) { + PWARN("fileURLWithPath threw %s: %s", + [[e name] UTF8String], [[e reason] UTF8String]); + return; } } - if (!url) - url = [NSURL - fileURLWithPath: [[[[docs_dir - stringByAppendingPathComponent: @"C"] - stringByAppendingPathComponent: subdir] - stringByAppendingPathComponent: tag] - stringByAppendingPathExtension: @"html"]]; - } /* It's a lot easier in a bundle! OSX finds the best translation for us. */ - else - url = [NSURL fileURLWithPath: [[NSBundle mainBundle] - pathForResource: tag - ofType: @"html" - inDirectory: subdir ]]; - + else { + @try { + url = [NSURL fileURLWithPath: [[NSBundle mainBundle] + pathForResource: tag + ofType: @"html" + inDirectory: subdir ]]; + } + @catch (NSException *e) { + PWARN("fileURLWithPath threw %s: %s", + [[e name] UTF8String], [[e reason] UTF8String]); + return; + } + } /* Now just open the URL in the default app for opening URLs */ if (url) [[NSWorkspace sharedWorkspace] openURL: url];