init: check property type in host_init_verifier
We have all of the 'type' information for properties available during
build time, so let's check this when setting properties in init.
Test: setprop apexd.status bad results in:
host_init_verifier: Command 'setprop apexd.status bad'
(out/soong/.intermediates/system/core/rootdir/init.rc/android_x86_core/init.rc:927)
failed: Property type check failed, value doesn't match expected type
'enum starting ready'
host_init_verifier: Failed to parse init script
'out/soong/.intermediates/system/core/rootdir/init.rc/android_x86_core/init.rc'
with 1 errors
Test: CF builds without that error
Change-Id: Iaad07747c09f4a10b2b816c455d6e8a485357ab9
diff --git a/init/check_builtins.cpp b/init/check_builtins.cpp
index 9d23921..bef6966 100644
--- a/init/check_builtins.cpp
+++ b/init/check_builtins.cpp
@@ -29,7 +29,9 @@
#include <android-base/strings.h>
#include "builtin_arguments.h"
+#include "host_init_verifier.h"
#include "interface_utils.h"
+#include "property_type.h"
#include "rlimit_parser.h"
#include "service.h"
#include "util.h"
@@ -171,6 +173,15 @@
<< "' from init; use the restorecon builtin directly";
}
+ const char* target_context = nullptr;
+ const char* type = nullptr;
+ property_info_area->GetPropertyInfo(name.c_str(), &target_context, &type);
+
+ if (!CheckType(type, value)) {
+ return Error() << "Property type check failed, value doesn't match expected type '"
+ << (type ?: "(null)") << "'";
+ }
+
return {};
}