https://github.com/NotPppp1116 created 
https://github.com/llvm/llvm-project/pull/209481

## What

Validate that generic iOS-derived `VersionMap` entries are JSON objects before 
parsing them.

## Why

Malformed `SDKSettings.json` data such as `"iOS_tvOS": "invalid"` made 
`getAsObject()` return null and was immediately dereferenced, crashing while 
loading the SDK metadata.

## Impact

Non-object derived-version mappings are ignored consistently with other 
unparseable generic mappings. Valid mappings are unchanged.

## Checks

- built `BasicTests`
- `DarwinSDKInfoTest.*` and `DarwinSDKInfo.*`: 9/9 passed
- focused ReturnGuard rescan reports no unchecked nullable dereference


>From 66de82f6053e1903b979dd0225393f4265938ab7 Mon Sep 17 00:00:00 2001
From: Pppp1116 <ACCOUNT1_NOREPLY>
Date: Tue, 14 Jul 2026 14:30:19 +0100
Subject: [PATCH] [clang] Ignore malformed derived SDK version mappings

---
 clang/lib/Basic/DarwinSDKInfo.cpp           |  5 ++++-
 clang/unittests/Basic/DarwinSDKInfoTest.cpp | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index 4e44da8febc3e..0b4e623e8fbf2 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -286,8 +286,11 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(std::string 
FilePath,
       if (Pair.first.compare_insensitive("ios") == 0) {
         llvm::Triple TT(llvm::Twine("--") + Pair.second.lower());
         if (TT.getOS() != llvm::Triple::UnknownOS) {
+          const auto *MappingObject = KV.getSecond().getAsObject();
+          if (!MappingObject)
+            continue;
           auto Mapping = RelatedTargetVersionMapping::parseJSON(
-              *KV.getSecond().getAsObject(), *MaximumDeploymentVersion);
+              *MappingObject, *MaximumDeploymentVersion);
           if (Mapping)
             VersionMappings[OSEnvPair(llvm::Triple::IOS,
                                       llvm::Triple::UnknownEnvironment,
diff --git a/clang/unittests/Basic/DarwinSDKInfoTest.cpp 
b/clang/unittests/Basic/DarwinSDKInfoTest.cpp
index 33d817c456403..2317b299b3f1b 100644
--- a/clang/unittests/Basic/DarwinSDKInfoTest.cpp
+++ b/clang/unittests/Basic/DarwinSDKInfoTest.cpp
@@ -223,6 +223,24 @@ TEST(DarwinSDKInfoTest, ParseAndTestMappingIOSDerived) {
       VersionTuple(15, 0, 99));
 }
 
+TEST(DarwinSDKInfoTest, IgnoreNonObjectIOSDerivedMapping) {
+  llvm::json::Object Obj;
+  Obj["CanonicalName"] = "appletvos15.0";
+  Obj["Version"] = "15.0";
+  Obj["MaximumDeploymentTarget"] = "15.0.99";
+  llvm::json::Object IOSToTvOS;
+  IOSToTvOS["iOS_tvOS"] = "not a mapping object";
+  Obj["VersionMap"] = std::move(IOSToTvOS);
+
+  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &Obj);
+  ASSERT_TRUE(SDKInfo);
+  EXPECT_EQ(SDKInfo->getVersion(), VersionTuple(15, 0));
+  EXPECT_EQ(SDKInfo->getVersionMapping(DarwinSDKInfo::OSEnvPair(
+                llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
+                llvm::Triple::TvOS, llvm::Triple::UnknownEnvironment)),
+            nullptr);
+}
+
 TEST(DarwinSDKInfoTest, MissingKeys) {
   llvm::json::Object Obj;
   ASSERT_FALSE(DarwinSDKInfo::parseDarwinSDKSettingsJSON("", &Obj));

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to