Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1536#discussion_r183800593
  
    --- Diff: core/sql/sqlcomp/PrivMgrPrivileges.cpp ---
    @@ -4445,6 +4503,50 @@ PrivStatus 
PrivMgrPrivileges::getPrivsFromAllGrantors(
     }
     
     
    +// 
----------------------------------------------------------------------------
    +// method: getRolesToCheck
    +//
    +// This method checks all the roles granted to the user and returns a comma
    +// separated list of those roles that have privileges on the target object.
    +// 
----------------------------------------------------------------------------
    +PrivStatus PrivMgrPrivileges::getRolesToCheck(
    +  const int32_t grantorID,
    +  const std::vector<int32_t> & roleIDs,
    +  const ComObjectType objectType,
    +  std::string &rolesWithPrivs)
    +{
    +  int32_t length;
    +  char roleName[MAX_DBUSERNAME_LEN + 1];
    +  std::vector<int_32> emptyRoleIDs;
    +  bool hasManagePrivPriv = false;
    +
    +  for (size_t r = 0; r < roleIDs.size(); r++)
    +  {
    +    PrivMgrDesc privsOfTheRole(roleIDs[r],true);
    +    if (getUserPrivs(objectType, roleIDs[r], emptyRoleIDs, privsOfTheRole,
    +                     hasManagePrivPriv) != STATUS_GOOD)
    +      return STATUS_ERROR;
    +
    +    if (!privsOfTheRole.isNull())
    +    {
    +      // just return what getAuthNameFromAuthID returns
    +      ComUser::getAuthNameFromAuthID(roleIDs[r],roleName, 
sizeof(roleName),length);
    +      if (r > 0)
    --- End diff --
    
    This doesn't look correct. I think you want a comma if you've already added 
a role to rolesWithPrivs. r > 0 means only that you've already processed one of 
the roleIDs array members. I think this code gives the wrong result if 
privsOfTheRole.isNull() is true for roleIDs[0].


---

Reply via email to