Skip to content

Commit

Permalink
When reading osx version via sysctl, ensure the result won't make dar…
Browse files Browse the repository at this point in the history
…ktable crash

Validate it's a string, and that has the right format.
  • Loading branch information
Matthieu Volat committed Sep 15, 2016
1 parent 6bb1d05 commit 71ff823
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/external/rawspeed/RawSpeed/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 71ff823

Please sign in to comment.