From 2dbfad71132cfc164257f53391b6ef7c6b3bfcd0 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Tue, 14 Jun 2016 18:04:05 +0900 Subject: [PATCH] svace Change-Id: I745773662dc8578fce7590bd1b3bc2bde3ede5ed Signed-off-by: sanghyeok.oh --- src/internal/naive_policy_checker.cpp | 2 +- src/internal/policy.cpp | 10 ++++++++-- src/libdbuspolicy1.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/internal/naive_policy_checker.cpp b/src/internal/naive_policy_checker.cpp index 8fc311a..6489a6d 100644 --- a/src/internal/naive_policy_checker.cpp +++ b/src/internal/naive_policy_checker.cpp @@ -60,7 +60,7 @@ bool NaivePolicyChecker::parseDecision(Decision decision, case Decision::DENY: return false; case Decision::CHECK: - std::sprintf(uid_str, "%lu", (unsigned long)uid); + std::snprintf(uid_str, sizeof(uid_str) - 1, "%lu", (unsigned long)uid); return ldp_cynara::Cynara::check(label, privilege, uid_str) == ldp_cynara::CynaraResult::ALLOW; } diff --git a/src/internal/policy.cpp b/src/internal/policy.cpp index da65a5c..20076e5 100644 --- a/src/internal/policy.cpp +++ b/src/internal/policy.cpp @@ -59,7 +59,7 @@ uid_t DbAdapter::convertToUid(const char* user) { struct passwd pwent; struct passwd *pwd; char buf[1024]; - if (getpwnam_r(user, &pwent, buf, sizeof(buf), &pwd) && pwd) + if (getpwnam_r(user, &pwent, buf, sizeof(buf), &pwd) || !pwd) return (uid_t)-1; return pwd->pw_uid; @@ -73,7 +73,7 @@ gid_t DbAdapter::convertToGid(const char* group) { struct group grent; struct group *gg; char buf[1024]; - if (getgrnam_r(group, &grent, buf, sizeof(buf), &gg) && gg) + if (getgrnam_r(group, &grent, buf, sizeof(buf), &gg) || !gg) return (gid_t)-1; return gg->gr_gid; @@ -259,6 +259,9 @@ ItemType ItemOwn::getType() const { } bool ItemOwn::match(const Item* item) const { const ItemOwn* it = dynamic_cast(item); + if (!it) + return false; + if (__is_prefix) { int i = 0; if (!__name) @@ -339,6 +342,9 @@ ItemSendReceive::~ItemSendReceive() { bool ItemSendReceive::match(const Item* item) const { const ItemSendReceive* it = dynamic_cast(item); + if (!it) + return false; + if (__type != MessageType::ANY && __type != it->__type) return false; diff --git a/src/libdbuspolicy1.c b/src/libdbuspolicy1.c index c274833..867ce2e 100644 --- a/src/libdbuspolicy1.c +++ b/src/libdbuspolicy1.c @@ -107,7 +107,7 @@ static uint64_t kdbus_unique_id(char const *name) unsigned i = 2; int c; while (!(c = name[++i] - '0')); - res = c; + res = (uint64_t)c; while ((c = (int)(name[++i]) - '0') > 0) res = res*10 + c; return res; -- 2.7.4