From fabea0a092b1891024875e6c5d7beca7c7f8ee4f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 23 Dec 2021 14:50:35 +0100 Subject: [PATCH] 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. --- vncviewer/MonitorArrangement.cxx | 24 ++++++++++++++++++------ 1 file 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]; -- 2.39.5