提交 114e6829 编写于 作者: O openharmony_ci 提交者: Gitee

!340 代码规范整改

Merge pull request !340 from 胡吉翔/security_20210720
...@@ -29,8 +29,10 @@ using namespace testing::ext; ...@@ -29,8 +29,10 @@ using namespace testing::ext;
static int TestSetUid() static int TestSetUid()
{ {
// Test the 'setuid' interface // Test the 'setuid' interface
int ret; int ret = 0;
uid_t ruid, euid, suid; uid_t ruid = 0;
uid_t euid = 0;
uid_t suid = 0;
// Step 1: Verify that UID is set to 0 // Step 1: Verify that UID is set to 0
ret = setuid(UID0); ret = setuid(UID0);
if (ret != 0) { if (ret != 0) {
...@@ -85,8 +87,10 @@ static int TestSetUid() ...@@ -85,8 +87,10 @@ static int TestSetUid()
static int TestSetREUid() static int TestSetREUid()
{ {
// Test the 'setreuid' interface // Test the 'setreuid' interface
int ret; int ret = 0;
uid_t ruid, euid, suid; uid_t ruid = 0;
uid_t euid = 0;
uid_t suid = 0;
// Step 1: Verify that UID is set to 0 // Step 1: Verify that UID is set to 0
ret = setreuid(UID0, UID0); ret = setreuid(UID0, UID0);
if (ret != 0) { if (ret != 0) {
...@@ -141,8 +145,10 @@ static int TestSetREUid() ...@@ -141,8 +145,10 @@ static int TestSetREUid()
static int TestSetRESUid() static int TestSetRESUid()
{ {
// Test the 'setresuid' interface // Test the 'setresuid' interface
int ret; int ret = 0;
uid_t ruid, euid, suid; uid_t ruid = 0;
uid_t euid = 0;
uid_t suid = 0;
// Step 1: Verify that UID is set to 0 // Step 1: Verify that UID is set to 0
ret = setresuid(UID0, UID0, UID0); ret = setresuid(UID0, UID0, UID0);
if (ret != 0) { if (ret != 0) {
...@@ -197,8 +203,13 @@ static int TestSetRESUid() ...@@ -197,8 +203,13 @@ static int TestSetRESUid()
static int TestSetUidAbnormal() static int TestSetUidAbnormal()
{ {
// Enter the exception parameter when invoke the 'setuid','setreuid','setresuid' interface // Enter the exception parameter when invoke the 'setuid','setreuid','setresuid' interface
int ret; int ret = 0;
uid_t newruid, neweuid, newsuid, ruid, euid, suid; uid_t newruid = 0;
uid_t neweuid = 0;
uid_t newsuid = 0;
uid_t ruid = 0;
uid_t euid = 0;
uid_t suid = 0;
// Obtain the ruid, euid, suid of the current process // Obtain the ruid, euid, suid of the current process
getresuid(&ruid, &euid, &suid); getresuid(&ruid, &euid, &suid);
// Step 1: Verify that UID is set to -100 with the 'setuid' interface // Step 1: Verify that UID is set to -100 with the 'setuid' interface
...@@ -243,8 +254,10 @@ static int TestSetUidAbnormal() ...@@ -243,8 +254,10 @@ static int TestSetUidAbnormal()
static int TestSetGid() static int TestSetGid()
{ {
// Test the 'setgid' interface // Test the 'setgid' interface
int ret; int ret = 0;
gid_t rgid, egid, sgid; gid_t rgid = 0;
gid_t egid = 0;
gid_t sgid = 0;
// Step 1: Verify that GID is set to 0 // Step 1: Verify that GID is set to 0
ret = setgid(GID0); ret = setgid(GID0);
if (ret != 0) { if (ret != 0) {
...@@ -299,8 +312,10 @@ static int TestSetGid() ...@@ -299,8 +312,10 @@ static int TestSetGid()
static int TestSetREGid() static int TestSetREGid()
{ {
// Test the 'setregid' interface // Test the 'setregid' interface
int ret; int ret = 0;
gid_t rgid, egid, sgid; gid_t rgid = 0;
gid_t egid = 0;
gid_t sgid = 0;
// Step 1: Verify that GID is set to 0 // Step 1: Verify that GID is set to 0
ret = setregid(GID0, GID0); ret = setregid(GID0, GID0);
if (ret != 0) { if (ret != 0) {
...@@ -355,8 +370,10 @@ static int TestSetREGid() ...@@ -355,8 +370,10 @@ static int TestSetREGid()
static int TestSetRESGid() static int TestSetRESGid()
{ {
// Test the 'setresgid' interface // Test the 'setresgid' interface
int ret; int ret = 0;
gid_t rgid, egid, sgid; gid_t rgid = 0;
gid_t egid = 0;
gid_t sgid = 0;
// Step 1: Verify that GID is set to 0 // Step 1: Verify that GID is set to 0
ret = setresgid(GID0, GID0, GID0); ret = setresgid(GID0, GID0, GID0);
if (ret != 0) { if (ret != 0) {
...@@ -411,8 +428,13 @@ static int TestSetRESGid() ...@@ -411,8 +428,13 @@ static int TestSetRESGid()
static int TestSetGidAbnormal() static int TestSetGidAbnormal()
{ {
// Enter the exception parameter when invoke the 'setgid','setregid','setresgid' interface // Enter the exception parameter when invoke the 'setgid','setregid','setresgid' interface
int ret; int ret = 0;
gid_t newrgid, newegid, newsgid, rgid, egid, sgid; gid_t newrgid = 0;
gid_t newegid = 0;
gid_t newsgid = 0;
gid_t rgid = 0;
gid_t egid = 0;
gid_t sgid = 0;
// Obtain the rgid, egid, sgid of the current process // Obtain the rgid, egid, sgid of the current process
getresgid(&rgid, &egid, &sgid); getresgid(&rgid, &egid, &sgid);
// Step 1: Verify that GID is set to -100 with the 'setgid' interface // Step 1: Verify that GID is set to -100 with the 'setgid' interface
...@@ -546,8 +568,13 @@ static int ChangeSensitiveInformation() ...@@ -546,8 +568,13 @@ static int ChangeSensitiveInformation()
*/ */
HWTEST_F(DacTestSuite, DACTest0010, Function | MediumTest | Level1) HWTEST_F(DacTestSuite, DACTest0010, Function | MediumTest | Level1)
{ {
int ret; int ret = 0;
uid_t ruid, euid, suid, newruid, neweuid, newsuid; uid_t ruid = 0;
uid_t euid = 0;
uid_t suid = 0;
uid_t newruid = 0;
uid_t neweuid = 0;
uid_t newsuid = 0;
// Preset action: Obtain the ruid, euid, suid of the current process // Preset action: Obtain the ruid, euid, suid of the current process
getresuid(&ruid, &euid, &suid); getresuid(&ruid, &euid, &suid);
// Step 1: Test the 'setuid' interface // Step 1: Test the 'setuid' interface
...@@ -578,8 +605,13 @@ HWTEST_F(DacTestSuite, DACTest0010, Function | MediumTest | Level1) ...@@ -578,8 +605,13 @@ HWTEST_F(DacTestSuite, DACTest0010, Function | MediumTest | Level1)
*/ */
HWTEST_F(DacTestSuite, DACTest0020, Function | MediumTest | Level1) HWTEST_F(DacTestSuite, DACTest0020, Function | MediumTest | Level1)
{ {
int ret; int ret = 0;
gid_t rgid, egid, sgid, newrgid, newegid, newsgid; gid_t rgid = 0;
gid_t egid = 0;
gid_t sgid = 0;
gid_t newrgid = 0;
gid_t newegid = 0;
gid_t newsgid = 0;
// Preset action: Obtain the rgid, egid, sgid of the current process // Preset action: Obtain the rgid, egid, sgid of the current process
getresgid(&rgid, &egid, &sgid); getresgid(&rgid, &egid, &sgid);
// Step 1: Test the 'setgid' interface // Step 1: Test the 'setgid' interface
...@@ -613,7 +645,7 @@ HWTEST_F(DacTestSuite, DACTest0030, Function | MediumTest | Level1) ...@@ -613,7 +645,7 @@ HWTEST_F(DacTestSuite, DACTest0030, Function | MediumTest | Level1)
int ret; int ret;
gid_t grouplist[SIZE255]; gid_t grouplist[SIZE255];
// Preset action: Obtain the groups of the current process // Preset action: Obtain the groups of the current process
int groupsize = getgroups(0, grouplist); size_t groupsize = getgroups(0, grouplist);
if (groupsize >= 0) { if (groupsize >= 0) {
getgroups(groupsize, grouplist); getgroups(groupsize, grouplist);
} else { } else {
...@@ -648,7 +680,7 @@ HWTEST_F(DacTestSuite, DACTest0040, Function | MediumTest | Level2) ...@@ -648,7 +680,7 @@ HWTEST_F(DacTestSuite, DACTest0040, Function | MediumTest | Level2)
int ret; int ret;
gid_t grouplist[SIZE255]; gid_t grouplist[SIZE255];
// Preset action: Obtain the groups of the current process // Preset action: Obtain the groups of the current process
int groupsize = getgroups(0, grouplist); size_t groupsize = getgroups(0, grouplist);
if (groupsize >= 0) { if (groupsize >= 0) {
getgroups(groupsize, grouplist); getgroups(groupsize, grouplist);
} else { } else {
...@@ -683,7 +715,7 @@ HWTEST_F(DacTestSuite, DACTest0050, Function | MediumTest | Level3) ...@@ -683,7 +715,7 @@ HWTEST_F(DacTestSuite, DACTest0050, Function | MediumTest | Level3)
int ret; int ret;
gid_t grouplist[SIZE255]; gid_t grouplist[SIZE255];
// Preset action: Obtain the groups of the current process // Preset action: Obtain the groups of the current process
int groupsize = getgroups(0, grouplist); size_t groupsize = getgroups(0, grouplist);
if (groupsize >= 0) { if (groupsize >= 0) {
getgroups(groupsize, grouplist); getgroups(groupsize, grouplist);
} else { } else {
...@@ -718,7 +750,7 @@ HWTEST_F(DacTestSuite, DACTest0060, Function | MediumTest | Level3) ...@@ -718,7 +750,7 @@ HWTEST_F(DacTestSuite, DACTest0060, Function | MediumTest | Level3)
int ret; int ret;
gid_t grouplist[SIZE255]; gid_t grouplist[SIZE255];
// Preset action: Obtain the groups of the current process // Preset action: Obtain the groups of the current process
int groupsize = getgroups(0, grouplist); size_t groupsize = getgroups(0, grouplist);
if (groupsize >= 0) { if (groupsize >= 0) {
getgroups(groupsize, grouplist); getgroups(groupsize, grouplist);
} else { } else {
...@@ -818,8 +850,11 @@ HWTEST_F(DacTestSuite, DACTest0070, Security | MediumTest | Level2) ...@@ -818,8 +850,11 @@ HWTEST_F(DacTestSuite, DACTest0070, Security | MediumTest | Level2)
HWTEST_F(DacTestSuite, DACTest0080, Function | MediumTest | Level2) HWTEST_F(DacTestSuite, DACTest0080, Function | MediumTest | Level2)
{ {
int ret; int ret;
uid_t ruid, euid, suid, newruid, neweuid, newsuid; uid_t ruid = 0; uid_t euid = 0; uid_t suid = 0;
gid_t rgid, egid, sgid, newrgid, newegid, newsgid, grouplist[SIZE255]; uid_t newruid = 0; uid_t neweuid = 0; uid_t newsuid = 0;
gid_t rgid = 0; gid_t egid = 0; gid_t sgid = 0;
gid_t newrgid = 0; gid_t newegid = 0; gid_t newsgid = 0;
gid_t grouplist[SIZE255];
// Preset action: Obtain the ruid, euid, suid of the current process // Preset action: Obtain the ruid, euid, suid of the current process
getresuid(&ruid, &euid, &suid); getresuid(&ruid, &euid, &suid);
// Preset action: Obtain the rgid, egid, sgid of the current process // Preset action: Obtain the rgid, egid, sgid of the current process
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册