!618 回退错误合入的解决getgroups的list比设置的list多一个gid问题的修改
Merge pull request !618 from wanghao-free/OpenHarmony_1.0.1_release
This commit is contained in:
commit
80e24fa9db
|
@ -683,12 +683,12 @@ int SysGetGroupID(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||||
static int SetGroups(int size, const int *safeList)
|
static int SetGroups(int listSize, const int *safeList, int size)
|
||||||
{
|
{
|
||||||
User *oldUser = NULL;
|
User *oldUser = NULL;
|
||||||
unsigned int intSave;
|
unsigned int intSave;
|
||||||
|
|
||||||
User *newUser = LOS_MemAlloc(m_aucSysMem1, sizeof(User) + size * sizeof(int));
|
User *newUser = LOS_MemAlloc(m_aucSysMem1, sizeof(User) + listSize * sizeof(int));
|
||||||
if (newUser == NULL) {
|
if (newUser == NULL) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
@ -696,11 +696,14 @@ static int SetGroups(int size, const int *safeList)
|
||||||
SCHEDULER_LOCK(intSave);
|
SCHEDULER_LOCK(intSave);
|
||||||
oldUser = OsCurrUserGet();
|
oldUser = OsCurrUserGet();
|
||||||
(VOID)memcpy_s(newUser, sizeof(User), oldUser, sizeof(User));
|
(VOID)memcpy_s(newUser, sizeof(User), oldUser, sizeof(User));
|
||||||
if (size != 0) {
|
if (safeList != NULL) {
|
||||||
(VOID)memcpy_s(newUser->groups, size * sizeof(int), safeList, size * sizeof(int));
|
(VOID)memcpy_s(newUser->groups, size * sizeof(int), safeList, size * sizeof(int));
|
||||||
}
|
}
|
||||||
|
if (listSize == size) {
|
||||||
newUser->groupNumber = size;
|
newUser->groups[listSize] = oldUser->gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
newUser->groupNumber = listSize + 1;
|
||||||
OsCurrProcessGet()->user = newUser;
|
OsCurrProcessGet()->user = newUser;
|
||||||
SCHEDULER_UNLOCK(intSave);
|
SCHEDULER_UNLOCK(intSave);
|
||||||
|
|
||||||
|
@ -721,7 +724,7 @@ static int GetGroups(int size, int list[])
|
||||||
SCHEDULER_UNLOCK(intSave);
|
SCHEDULER_UNLOCK(intSave);
|
||||||
|
|
||||||
listSize = groupCount * sizeof(int);
|
listSize = groupCount * sizeof(int);
|
||||||
if ((size == 0) || (groupCount == 0)) {
|
if (size == 0) {
|
||||||
return groupCount;
|
return groupCount;
|
||||||
} else if (list == NULL) {
|
} else if (list == NULL) {
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
@ -779,6 +782,7 @@ int SysSetGroups(int size, const int list[])
|
||||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||||
int ret;
|
int ret;
|
||||||
int gid;
|
int gid;
|
||||||
|
int listSize = size;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
int *safeList = NULL;
|
int *safeList = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -809,14 +813,16 @@ int SysSetGroups(int size, const int list[])
|
||||||
}
|
}
|
||||||
gid = OsCurrUserGet()->gid;
|
gid = OsCurrUserGet()->gid;
|
||||||
for (count = 0; count < size; count++) {
|
for (count = 0; count < size; count++) {
|
||||||
if (safeList[count] < 0) {
|
if (safeList[count] == gid) {
|
||||||
|
listSize = size - 1;
|
||||||
|
} else if (safeList[count] < 0) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetGroups(size, safeList);
|
ret = SetGroups(listSize, safeList, size);
|
||||||
EXIT:
|
EXIT:
|
||||||
if (safeList != NULL) {
|
if (safeList != NULL) {
|
||||||
(void)LOS_MemFree(m_aucSysMem1, safeList);
|
(void)LOS_MemFree(m_aucSysMem1, safeList);
|
||||||
|
|
Loading…
Reference in New Issue