diff options
author | Pierre Ossman <ossman@cendio.se> | 2021-12-23 14:50:35 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2021-12-23 14:50:35 +0100 |
commit | fabea0a092b1891024875e6c5d7beca7c7f8ee4f (patch) | |
tree | 0ed2111df1d8e701acb3518737046510f6acbe4a | |
parent | 789845ffdc153deab19c2c740daddb40a2d7699c (diff) | |
download | tigervnc-fabea0a092b1891024875e6c5d7beca7c7f8ee4f.tar.gz tigervnc-fabea0a092b1891024875e6c5d7beca7c7f8ee4f.zip |
Be more paranoid about monitor info
These function are not guaranteed to succeed, and we've had reports that
they fail on ARM. So make sure we more properly check return values.
-rw-r--r-- | vncviewer/MonitorArrangement.cxx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/vncviewer/MonitorArrangement.cxx b/vncviewer/MonitorArrangement.cxx index e075d173..055a91cc 100644 --- a/vncviewer/MonitorArrangement.cxx +++ b/vncviewer/MonitorArrangement.cxx @@ -406,6 +406,12 @@ std::string MonitorArrangement::get_monitor_name(int m) #elif defined(__APPLE__) CGDisplayCount count; CGDirectDisplayID displays[16]; + + CGDirectDisplayID displayID; + CFDictionaryRef info; + CFDictionaryRef dict; + CFIndex dict_len; + std::string name; if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess) @@ -418,14 +424,20 @@ std::string MonitorArrangement::get_monitor_name(int m) return ""; // Notice: Here we assume indices to be ordered the same as in FLTK (we rely on that in cocoa.mm as well). - CGDirectDisplayID displayID = displays[m]; + displayID = displays[m]; + + info = IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), + kIODisplayOnlyPreferredName); + if (info == NULL) + return ""; - CFDictionaryRef info = IODisplayCreateInfoDictionary( - /* display = */ CGDisplayIOServicePort(displayID), - /* options = */ kIODisplayOnlyPreferredName); + dict = (CFDictionaryRef) CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); + if (dict == NULL) { + CFRelease(info); + return ""; + } - CFDictionaryRef dict = (CFDictionaryRef) CFDictionaryGetValue(info, CFSTR(kDisplayProductName)); - CFIndex dict_len = CFDictionaryGetCount(dict); + dict_len = CFDictionaryGetCount(dict); if (dict_len > 0) { CFTypeRef * names = new CFTypeRef[dict_len]; |