Loading init/property_service.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <sys/types.h> #include <sys/un.h> #include <unistd.h> #include <wchar.h> #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> Loading Loading @@ -160,6 +161,12 @@ static uint32_t PropertySetImpl(const std::string& name, const std::string& valu return PROP_ERROR_INVALID_VALUE; } if (mbstowcs(nullptr, value.data(), 0) == static_cast<std::size_t>(-1)) { LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: " << "value not a UTF8 encoded string"; return PROP_ERROR_INVALID_VALUE; } prop_info* pi = (prop_info*) __system_property_find(name.c_str()); if (pi != nullptr) { // ro.* properties are actually "write-once". Loading init/property_service_test.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -21,8 +21,11 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> #include <android-base/properties.h> #include <gtest/gtest.h> using android::base::SetProperty; namespace android { namespace init { Loading Loading @@ -50,5 +53,19 @@ TEST(property_service, very_long_name_35166374) { ASSERT_EQ(0, close(fd)); } TEST(property_service, non_utf8_value) { ASSERT_TRUE(SetProperty("property_service_utf8_test", "base_success")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\x80")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xC2\x01")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xE0\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xE0\xA0\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x01\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x90\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x90\x80\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x90\x80")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "ab\xF0\x90\x80\x80qe\xF0\x90\x80")); EXPECT_TRUE(SetProperty("property_service_utf8_test", "\xF0\x90\x80\x80")); } } // namespace init } // namespace android Loading
init/property_service.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <sys/types.h> #include <sys/un.h> #include <unistd.h> #include <wchar.h> #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> Loading Loading @@ -160,6 +161,12 @@ static uint32_t PropertySetImpl(const std::string& name, const std::string& valu return PROP_ERROR_INVALID_VALUE; } if (mbstowcs(nullptr, value.data(), 0) == static_cast<std::size_t>(-1)) { LOG(ERROR) << "property_set(\"" << name << "\", \"" << value << "\") failed: " << "value not a UTF8 encoded string"; return PROP_ERROR_INVALID_VALUE; } prop_info* pi = (prop_info*) __system_property_find(name.c_str()); if (pi != nullptr) { // ro.* properties are actually "write-once". Loading
init/property_service_test.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -21,8 +21,11 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> #include <android-base/properties.h> #include <gtest/gtest.h> using android::base::SetProperty; namespace android { namespace init { Loading Loading @@ -50,5 +53,19 @@ TEST(property_service, very_long_name_35166374) { ASSERT_EQ(0, close(fd)); } TEST(property_service, non_utf8_value) { ASSERT_TRUE(SetProperty("property_service_utf8_test", "base_success")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\x80")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xC2\x01")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xE0\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xE0\xA0\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x01\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x90\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x90\x80\xFF")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "\xF0\x90\x80")); EXPECT_FALSE(SetProperty("property_service_utf8_test", "ab\xF0\x90\x80\x80qe\xF0\x90\x80")); EXPECT_TRUE(SetProperty("property_service_utf8_test", "\xF0\x90\x80\x80")); } } // namespace init } // namespace android