From f9fae16456c30479b0cb9317e57200af36795785 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Mon, 12 May 2008 10:36:44 -0700 Subject: [PATCH] XQuartz: Added some version checking protection so we don't trigger an infinite exec loop with new /usr/X11/bin/Xquartz and older X11.app (cherry picked from commit 78032815aeb10c22ff45b49702e9c9df82ab471c) --- hw/xquartz/bundle/Info.plist | 4 +++ hw/xquartz/mach-startup/stub.c | 46 +++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/hw/xquartz/bundle/Info.plist b/hw/xquartz/bundle/Info.plist index 4b0830f0e..30bb3c891 100644 --- a/hw/xquartz/bundle/Info.plist +++ b/hw/xquartz/bundle/Info.plist @@ -20,6 +20,10 @@ APPL CFBundleShortVersionString 2.3.0 + CFBundleVersion + 2.3.0 + CFBundleVersionString + 2.3.0 CFBundleSignature x11a CSResourcesFileMapped diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c index 70f222c27..3be5f6568 100644 --- a/hw/xquartz/mach-startup/stub.c +++ b/hw/xquartz/mach-startup/stub.c @@ -43,33 +43,55 @@ static char x11_path[PATH_MAX + 1]; static void set_x11_path() { CFURLRef appURL = NULL; + CFBundleRef bundle = NULL; OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL); - + UInt32 ver; + switch (osstatus) { case noErr: if (appURL == NULL) { - fprintf(stderr, "xinit: Invalid response from LSFindApplicationForInfo(%s)\n", + fprintf(stderr, "Xquartz: Invalid response from LSFindApplicationForInfo(%s)\n", kX11AppBundleId); exit(1); } - - if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) { - fprintf(stderr, "xinit: Error resolving URL for %s\n", kX11AppBundleId); - exit(2); + + bundle = CFBundleCreate(NULL, appURL); + if(!bundle) { + fprintf(stderr, "Xquartz: Null value returned from CFBundleCreate().\n"); + exit(2); } - + + if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) { + fprintf(stderr, "Xquartz: Error resolving URL for %s\n", kX11AppBundleId); + exit(3); + } + + ver = CFBundleGetVersionNumber(bundle); + if(ver < 0x02308000) { + CFStringRef versionStr = CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey); + const char * versionCStr = "Unknown"; + + if(versionStr) + versionCStr = CFStringGetCStringPtr(versionStr, kCFStringEncodingMacRoman); + + fprintf(stderr, "Xquartz: Could not find a new enough X11.app LSFindApplicationForInfo() returned\n"); + fprintf(stderr, " X11.app = %s\n", x11_path); + fprintf(stderr, " Version = %s (%x), Expected Version > 2.3.0\n", versionCStr, (unsigned)ver); + exit(9); + } + strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path)); #ifdef DEBUG - fprintf(stderr, "XQuartz: X11.app = %s\n", x11_path); + fprintf(stderr, "Xquartz: X11.app = %s\n", x11_path); #endif break; case kLSApplicationNotFoundErr: - fprintf(stderr, "XQuartz: Unable to find application for %s\n", kX11AppBundleId); - exit(4); + fprintf(stderr, "Xquartz: Unable to find application for %s\n", kX11AppBundleId); + exit(10); default: - fprintf(stderr, "XQuartz: Unable to find application for %s, error code = %d\n", + fprintf(stderr, "Xquartz: Unable to find application for %s, error code = %d\n", kX11AppBundleId, (int)osstatus); - exit(5); + exit(11); } }