Loading cmds/servicemanager/ServiceManager.cpp +17 −2 Original line number Original line Diff line number Diff line Loading @@ -63,6 +63,21 @@ Status ServiceManager::checkService(const std::string& name, sp<IBinder>* outBin return Status::ok(); return Status::ok(); } } bool isValidServiceName(const std::string& name) { if (name.size() == 0) return false; if (name.size() > 127) return false; for (char c : name) { if (c == '_' || c == '-' || c == '.') continue; if (c >= 'a' && c <= 'z') continue; if (c >= 'A' && c <= 'Z') continue; if (c >= '0' && c <= '9') continue; return false; } return true; } Status ServiceManager::addService(const std::string& name, const sp<IBinder>& binder, bool allowIsolated, int32_t dumpPriority) { Status ServiceManager::addService(const std::string& name, const sp<IBinder>& binder, bool allowIsolated, int32_t dumpPriority) { auto ctx = mAccess->getCallingContext(name); auto ctx = mAccess->getCallingContext(name); Loading @@ -79,8 +94,8 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); } } // match legacy rules if (!isValidServiceName(name)) { if (name.size() == 0 || name.size() > 127) { LOG(ERROR) << "Invalid service name: " << name; return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); } } Loading cmds/servicemanager/test_sm.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -82,6 +82,12 @@ TEST(AddService, TooLongNameDisallowed) { IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()); IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()); } } TEST(AddService, WeirdCharactersDisallowed) { auto sm = getPermissiveServiceManager(); EXPECT_FALSE(sm->addService("happy$foo$foo", getBinder(), false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()); } TEST(AddService, AddNullServiceDisallowed) { TEST(AddService, AddNullServiceDisallowed) { auto sm = getPermissiveServiceManager(); auto sm = getPermissiveServiceManager(); EXPECT_FALSE(sm->addService("foo", nullptr, false /*allowIsolated*/, EXPECT_FALSE(sm->addService("foo", nullptr, false /*allowIsolated*/, Loading Loading
cmds/servicemanager/ServiceManager.cpp +17 −2 Original line number Original line Diff line number Diff line Loading @@ -63,6 +63,21 @@ Status ServiceManager::checkService(const std::string& name, sp<IBinder>* outBin return Status::ok(); return Status::ok(); } } bool isValidServiceName(const std::string& name) { if (name.size() == 0) return false; if (name.size() > 127) return false; for (char c : name) { if (c == '_' || c == '-' || c == '.') continue; if (c >= 'a' && c <= 'z') continue; if (c >= 'A' && c <= 'Z') continue; if (c >= '0' && c <= '9') continue; return false; } return true; } Status ServiceManager::addService(const std::string& name, const sp<IBinder>& binder, bool allowIsolated, int32_t dumpPriority) { Status ServiceManager::addService(const std::string& name, const sp<IBinder>& binder, bool allowIsolated, int32_t dumpPriority) { auto ctx = mAccess->getCallingContext(name); auto ctx = mAccess->getCallingContext(name); Loading @@ -79,8 +94,8 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); } } // match legacy rules if (!isValidServiceName(name)) { if (name.size() == 0 || name.size() > 127) { LOG(ERROR) << "Invalid service name: " << name; return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); } } Loading
cmds/servicemanager/test_sm.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -82,6 +82,12 @@ TEST(AddService, TooLongNameDisallowed) { IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()); IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()); } } TEST(AddService, WeirdCharactersDisallowed) { auto sm = getPermissiveServiceManager(); EXPECT_FALSE(sm->addService("happy$foo$foo", getBinder(), false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()); } TEST(AddService, AddNullServiceDisallowed) { TEST(AddService, AddNullServiceDisallowed) { auto sm = getPermissiveServiceManager(); auto sm = getPermissiveServiceManager(); EXPECT_FALSE(sm->addService("foo", nullptr, false /*allowIsolated*/, EXPECT_FALSE(sm->addService("foo", nullptr, false /*allowIsolated*/, Loading