From 87185d9ab8fdc6c1c8e2ccdf9339e4afe405a604 Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Mon, 27 Apr 2026 23:08:08 +0200 Subject: [PATCH] fix(#458): avoid null pointer while extracting plist root dictionary --- .../discovery/fileformats/OsxPlistFile.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/owlplug-client/src/main/java/com/owlplug/plugin/tasks/discovery/fileformats/OsxPlistFile.java b/owlplug-client/src/main/java/com/owlplug/plugin/tasks/discovery/fileformats/OsxPlistFile.java index 73273ffd..b468b1d3 100644 --- a/owlplug-client/src/main/java/com/owlplug/plugin/tasks/discovery/fileformats/OsxPlistFile.java +++ b/owlplug-client/src/main/java/com/owlplug/plugin/tasks/discovery/fileformats/OsxPlistFile.java @@ -35,7 +35,7 @@ public class OsxPlistFile { private final Logger log = LoggerFactory.getLogger(this.getClass()); - private File plist; + private final File plist; public OsxPlistFile(File plist) { super(); @@ -44,11 +44,27 @@ public OsxPlistFile(File plist) { public void bindProperties(Plugin plugin) { - try { - NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(plist); + // Ensure plist class constructor input is not null + if (plist == null) { + log.error("Plist file/input is null, cannot bind properties."); + return; + } + + NSObject rootObject = PropertyListParser.parse(plist); + + // Ensure parsed result is a NSDictionary + // Some execution shown that it could be null + if (!(rootObject instanceof NSDictionary)) { + log.error("Plist root is not a NSDictionary, actual type: {}", + rootObject == null ? "null" : rootObject.getClass().getName()); + return; + } + + NSDictionary rootDict = (NSDictionary) rootObject; + NSObject nsBundleId = rootDict.objectForKey("CFBundleIdentifier"); - NSObject nsBundleVersion = rootDict.objectForKey("CFBun" + "dleShortVersionString"); + NSObject nsBundleVersion = rootDict.objectForKey("CFBundleShortVersionString"); if (nsBundleVersion == null) { nsBundleVersion = rootDict.objectForKey("CFBundleVersion"); @@ -59,9 +75,10 @@ public void bindProperties(Plugin plugin) { if (nsBundleVersion != null) { plugin.setVersion(nsBundleVersion.toString()); } - } catch (IOException | PropertyListFormatException | ParseException | ParserConfigurationException - | SAXException e) { - log.error("Error while binding plugin properties from Plist file", e); + + } catch (IOException | PropertyListFormatException | ParseException + | ParserConfigurationException | SAXException e) { + log.error("Error while binding plugin properties from Plist file", e); } } }