return SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT;
}
- if (app_name && !appNameString.empty() && !(*app_name = strdup(appNameString.c_str()))) {
+ char *appName = nullptr;
+ if (app_name && !appNameString.empty() && !(appName = strdup(appNameString.c_str()))) {
LogError("Memory allocation in strdup failed.");
return SECURITY_MANAGER_ERROR_MEMORY;
}
- if (pkg_name && !(*pkg_name = strdup(pkgNameString.c_str()))) {
- LogError("Memory allocation in strdup failed.");
- return SECURITY_MANAGER_ERROR_MEMORY;
+ char *pkgName = nullptr;
+ if (pkg_name) {
+ if (!(pkgName = strdup(pkgNameString.c_str()))) {
+ free(appName);
+ LogError("Memory allocation in strdup failed.");
+ return SECURITY_MANAGER_ERROR_MEMORY;
+ }
+ *pkg_name = pkgName;
}
+
+ if (app_name)
+ *app_name = appName;
+
return SECURITY_MANAGER_SUCCESS;
}
#include <agent.h>
static LicenseManager::Agent *s_agentPtr = nullptr;
+class SigAgentPtrSetter {
+public:
+ explicit SigAgentPtrSetter(LicenseManager::Agent *p) {
+ s_agentPtr = p;
+ }
+ ~SigAgentPtrSetter() {
+ s_agentPtr = nullptr;
+ }
+};
void kill_handler(int sig UNUSED) {
ALOGD("License manager service is going down now");
ALOGE("cynara initialization failed");
return -1;
}
- s_agentPtr = &agent;
+ SigAgentPtrSetter sigAgentPtrSetter{&agent};
ret = sd_notify(0, "READY=1");
if (ret == 0) {
ALOGW("Agent was not configured to notify its status");
ALOGE("sd_notify failed: [" << ret << "]");
}
agent.mainLoop();
- s_agentPtr = nullptr;
} catch (const std::exception &e) {
- s_agentPtr = nullptr;
std::string error = e.what();
ALOGE("Exception: %s", error.c_str());
}
{
int sockfd;
- if (desc.serviceHandlerPath.size() >= sizeof(static_cast<sockaddr_un*>(0)->sun_path) /
- sizeof(decltype(desc.serviceHandlerPath)::value_type)) {
+ static_assert(1 == sizeof(*desc.serviceHandlerPath.c_str()));
+ if (desc.serviceHandlerPath.size() >= sizeof(static_cast<sockaddr_un*>(0)->sun_path)) {
LogError("Service handler path too long: " << desc.serviceHandlerPath.size());
ThrowMsg(Exception::InitFailed,
"Service handler path too long: " << desc.serviceHandlerPath.size());
BOOST_REQUIRE(SECURITY_MANAGER_SUCCESS == FS::overwriteFile(PRIVILEGE_DB_EXAMPLE_RULES, TEST_DB_PATH));
BOOST_REQUIRE(!system(TEST_RULES_LOADER_CMD " | LC_ALL=C sort > /tmp/out"));
BOOST_REQUIRE(fileContentsSame("/tmp/out", PRIVILEGE_DB_EXAMPLE_RULES_OUTPUT));
- remove("/tmp/out");
+ BOOST_REQUIRE(!remove("/tmp/out"));
}
BOOST_AUTO_TEST_CASE(T1570_fallback_canonicity) {