From f6fec2dc0e51fd7fa017d1c04b21be9c99cee028 Mon Sep 17 00:00:00 2001 From: Matthieu Volat Date: Thu, 15 Sep 2016 12:34:43 +0200 Subject: [PATCH 1/2] Use a non-deprecated way of getting OSX version Gestalt stuff from Carbon is deprecated, use a more stable sysctl call to get OSX version, but keep the previous version format. --- src/external/rawspeed/RawSpeed/Common.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/external/rawspeed/RawSpeed/Common.cpp b/src/external/rawspeed/RawSpeed/Common.cpp index afd06a3274bf..1acb80eaa896 100644 --- a/src/external/rawspeed/RawSpeed/Common.cpp +++ b/src/external/rawspeed/RawSpeed/Common.cpp @@ -24,14 +24,20 @@ #if defined(__APPLE__) -#include +#include +#include +#include +#include int macosx_version() { - SInt32 gestalt_version; static int ver = 0; // cached - if (0 == ver && (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr)) { - ver = gestalt_version; + char str[256]; + size_t strsize = sizeof(str); + if (0 == ver && sysctlbyname("kern.osrelease", str, &strsize, NULL, 0) == 0) { + // sysctl is major.minor.path + *strchr(str, '.') = '\0'; + ver = 0x1000 + strtol(str, NULL, 10)*10; } return ver; } @@ -77,4 +83,4 @@ void writeLog(int priority, const char *format, ...) va_end(args); } -} // Namespace RawSpeed \ No newline at end of file +} // Namespace RawSpeed From 71ff8234a5b1576f52afb990eec40217f85d434d Mon Sep 17 00:00:00 2001 From: Matthieu Volat Date: Thu, 15 Sep 2016 13:54:37 +0200 Subject: [PATCH 2/2] When reading osx version via sysctl, ensure the result won't make darktable crash Validate it's a string, and that has the right format. --- src/external/rawspeed/RawSpeed/Common.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/external/rawspeed/RawSpeed/Common.cpp b/src/external/rawspeed/RawSpeed/Common.cpp index 1acb80eaa896..fe01fc578142 100644 --- a/src/external/rawspeed/RawSpeed/Common.cpp +++ b/src/external/rawspeed/RawSpeed/Common.cpp @@ -35,9 +35,13 @@ int macosx_version() char str[256]; size_t strsize = sizeof(str); if (0 == ver && sysctlbyname("kern.osrelease", str, &strsize, NULL, 0) == 0) { - // sysctl is major.minor.path - *strchr(str, '.') = '\0'; - ver = 0x1000 + strtol(str, NULL, 10)*10; + // kern.osrelease is a string formated as "Major.Minor.Patch" + if (memchr(str, '\0', strsize) != NULL) { + int major, minor, patch; + if (sscanf(str, "%d.%d.%d", &major, &minor, &patch) == 3) { + ver = 0x1000 + major*10; + } + } } return ver; }