aidl: verify enum backing type
Before, 'boolean' was allowed. Now we restrict this to contain only the
values which are supported.
Fixes: 201586394
Test: aidl_unittests
Change-Id: Id15a87b54ae841238eb41b6b0a8f802b74165222
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 18c2710..694a8aa 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -1425,10 +1425,21 @@
backing_type_ =
std::make_unique<AidlTypeSpecifier>(AIDL_LOCATION_HERE, "byte", false, nullptr, Comments{});
}
- // Autofill() is called after type resolution, we resolve the backing type manually.
- if (!backing_type_->Resolve(typenames, nullptr)) {
- AIDL_ERROR(this) << "Invalid backing type: " << backing_type_->GetName();
+
+ // we only support/test a few backing types, so make sure this is a supported
+ // one (otherwise boolean might work, which isn't supported/tested in all
+ // backends)
+ static std::set<string> kBackingTypes = {"byte", "int", "long"};
+ if (kBackingTypes.find(backing_type_->GetName()) == kBackingTypes.end()) {
+ AIDL_ERROR(this) << "Invalid backing type: " << backing_type_->GetName()
+ << ". Backing type must be one of: " << Join(kBackingTypes, ", ");
+ return false;
}
+
+ // Autofill() is called before type resolution, we resolve the backing type manually.
+ AIDL_FATAL_IF(!backing_type_->Resolve(typenames, nullptr),
+ "supporting backing types must resolve");
+
return true;
}