OSDN Git Service

OSI: Protect cutils/properties.h from direct calls
authorMyles Watson <mylesgw@google.com>
Fri, 16 Feb 2018 21:11:04 +0000 (13:11 -0800)
committerMyles Watson <mylesgw@google.com>
Sat, 17 Feb 2018 01:00:51 +0000 (01:00 +0000)
Bug: None
Test: compile, no calls to property_get outside of libosi
      change PROPERTY_VALUE_MAX in osi/include/properties.h
      -> doesn't compile
Change-Id: I18c7b861782b1df4878da032ae3f0340dffdecab

osi/include/properties.h
osi/src/properties.cc
service/Android.bp
service/main.cc

index 5dc9781..ee99e99 100644 (file)
 #pragma once
 
 #include <cstdint>
-#if defined(OS_GENERIC)
+
 #define PROPERTY_VALUE_MAX 92
-#else
-#include <cutils/properties.h>
-#endif  // defined(OS_GENERIC)
+#define BUILD_SANITY_PROPERTY_VALUE_MAX 92
 
 // Get value associated with key |key| into |value|.
 // Returns the length of the value which will never be greater than
index acfb179..d2bdd28 100644 (file)
 
 #include "osi/include/properties.h"
 
+#if !defined(OS_GENERIC)
+#undef PROPERTY_VALUE_MAX
+#include <cutils/properties.h>
+#if BUILD_SANITY_PROPERTY_VALUE_MAX != PROPERTY_VALUE_MAX
+#error "PROPERTY_VALUE_MAX from osi/include/properties.h != the Android value"
+#endif  // GENERIC_PROPERTY_VALUE_MAX != PROPERTY_VALUE_MAX
+#endif  // !defined(OS_GENERIC)
+
 int osi_property_get(const char* key, char* value, const char* default_value) {
 #if defined(OS_GENERIC)
   /* For linux right now just return default value, if present */
index 91fab48..d24e0fa 100644 (file)
@@ -75,6 +75,7 @@ cc_binary {
         "libbluetooth-binder-common",
         "libbtcore",
         "libbluetooth-types",
+        "libosi",
     ],
 
     shared_libs: [
index b850d04..019098e 100644 (file)
@@ -55,16 +55,14 @@ int main(int argc, char* argv[]) {
     return EXIT_SUCCESS;
   }
 
-#if !defined(OS_GENERIC)
   // TODO(armansito): Remove Chromecast specific property out of here. This
   // should just be obtained from global config.
   char disable_value[PROPERTY_VALUE_MAX];
-  int status = property_get(kDisableProperty, disable_value, nullptr);
+  int status = osi_property_get(kDisableProperty, disable_value, nullptr);
   if (status && !strcmp(disable_value, "1")) {
     LOG(INFO) << "service disabled";
     return EXIT_SUCCESS;
   }
-#endif  // !defined(OS_GENERIC)
 
   if (!bluetooth::Daemon::Initialize()) {
     LOG(ERROR) << "Failed to initialize Daemon";