From 1a2cefc887cbab1ca22929117576ab39a411bd82 Mon Sep 17 00:00:00 2001 From: Kazimierz Krosman Date: Thu, 1 Sep 2016 18:27:30 +0900 Subject: [PATCH] Bugfix:wrong gid/uid converting if input is as below, DbAdapter::convertToUid / Gid function return 0, not -1. Change-Id: I4a36e0b387bd532b72e37a339c1a308ad8bf55f8 --- src/internal/policy.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/internal/policy.cpp b/src/internal/policy.cpp index 20076e5..2fc5b2f 100755 --- a/src/internal/policy.cpp +++ b/src/internal/policy.cpp @@ -51,9 +51,12 @@ DbAdapter::DbAdapter(NaivePolicyDb& system, NaivePolicyDb& session) } uid_t DbAdapter::convertToUid(const char* user) { + long val = -1; errno = 0; - long val = std::strtol(user, NULL, 10); - if (!errno) + val = std::strtol(user, NULL, 10); + if (!errno && (val != 0 )) + return (uid_t)val; + if ((val == 0 && user[0] == '0' && user[1] == 0)) return (uid_t)val; struct passwd pwent; @@ -66,10 +69,14 @@ uid_t DbAdapter::convertToUid(const char* user) { } gid_t DbAdapter::convertToGid(const char* group) { + long val = -1; errno = 0; - long val = std::strtol(group, NULL, 10); - if (!errno) + val = std::strtol(group, NULL, 10); + if (!errno && (val != 0)) + return (gid_t)val; + if ((val == 0 && group[0] == '0' && group[1] == 0)) return (gid_t)val; + struct group grent; struct group *gg; char buf[1024]; -- 2.7.4