From: Caspar Zhang <czhang@redhat.com>
To: Garrett Cooper <yanegomi@gmail.com>
Cc: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH] syscalls: acct01: fix testcases [was: Re: [PATCH] Add tst_require_root to acct01 testcase.]
Date: Fri, 04 Mar 2011 01:16:39 +0800 [thread overview]
Message-ID: <4D6FCCF7.2010101@redhat.com> (raw)
In-Reply-To: <AANLkTikt-TBmgTSqcRT4OY21udzxpuq-s0yGqirMrWFr@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3549 bytes --]
On 01/21/2011 04:28 PM, Garrett Cooper wrote:
> On Thu, Jan 20, 2011 at 5:30 AM, Cristian Greco <cristian@regolo.cc> wrote:
>> > Hi,
>> >
>> > [ please keep CC as I'm not currently subscribed to the list ]
>> >
>> > please find attached a small fix to check for root privileges in
>> > acct(2) testcase (syscalls/acct/acct01.c).
> Thanks for spotting the issue. I've fixed it, added a few more
> testcases, and discovered what appears to be a kernel bug on 2.6.34
> (acct("/tmp/does/not/exist") should fail with == -1 and errno ==
> ENOTDIR) :)...
> Cheers,
> -Garrett
a follow-up fix for http://article.gmane.org/gmane.linux.ltp/13576 .
In fact, it's not a kernel bug of ENOTDIR's failure. ENOTDIR means that
you setup a string as directory in argument, but it is actually a file.
The patch fixes this failure. The result of given path
/tmp/does/not/exist should be expected as ENOENT.
And also, there is a mistake in EPERM case, to restore the permissions,
SAFE_SETUID should be used instead of SAFE_SETGID, else it will never
recover the permissions.
Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
testcases/kernel/syscalls/acct/acct01.c | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/testcases/kernel/syscalls/acct/acct01.c
b/testcases/kernel/syscalls/acct/acct01.c
index 5314f4f..324d423 100644
--- a/testcases/kernel/syscalls/acct/acct01.c
+++ b/testcases/kernel/syscalls/acct/acct01.c
@@ -96,26 +96,36 @@ int main(int argc, char *argv[])
setup();
+ /* EISDIR */
if (acct("/") == -1 && errno == EISDIR)
tst_resm(TPASS, "Failed with EISDIR as expected");
else
tst_brkm(TFAIL|TERRNO, cleanup,
"didn't fail as expected; expected EISDIR");
+ /* EACCES */
if (acct("/dev/null") == -1 && errno == EACCES)
tst_resm(TPASS, "Failed with EACCES as expected");
else
tst_brkm(TFAIL|TERRNO, cleanup,
"didn't fail as expected; expected EACCES");
- if (acct("/tmp/does/not/exist") == -1 && errno == ENOTDIR)
+ /* ENOENT */
+ if (acct("/tmp/does/not/exist") == -1 && errno == ENOENT)
+ tst_resm(TPASS, "Failed with ENOENT as expected");
+ else
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "didn't fail as expected; expected ENOENT");
+
+ /* ENOTDIR */
+ if (acct("/etc/fstab/") == -1 && errno == ENOTDIR)
tst_resm(TPASS, "Failed with ENOTDIR as expected");
else
tst_brkm(TFAIL|TERRNO, cleanup,
"didn't fail as expected; expected ENOTDIR");
+ /* EPERM */
sprintf(tmpbuf, "./%s.%d", TCID, getpid());
-
fd = SAFE_CREAT(cleanup, tmpbuf, 0777);
SAFE_CLOSE(cleanup, fd);
@@ -123,25 +133,17 @@ int main(int argc, char *argv[])
tst_brkm(TBROK|TERRNO, cleanup, "acct failed unexpectedly");
pwent = SAFE_GETPWNAM(cleanup, "nobody");
-
SAFE_SETEUID(cleanup, pwent->pw_uid);
if (acct(tmpbuf) == -1 && errno == EPERM)
- tst_resm(TPASS, "acct failed as expected with EPERM");
+ tst_resm(TPASS, "Failed with EPERM as expected");
else
tst_brkm(TBROK|TERRNO, cleanup,
- "acct didn't fail as expected with EPERM");
-
- SAFE_SETEGID(cleanup, 0);
+ "didn't fail as expected; expected EPERM");
+ SAFE_SETEUID(cleanup, 0);
SAFE_UNLINK(cleanup, tmpbuf);
- if (acct(tmpbuf) == -1 && errno == ENOENT)
- tst_resm(TPASS, "acct failed as expected with ENOENT");
- else
- tst_brkm(TBROK|TERRNO, cleanup,
- "acct didn't fail as expected with ENOENT");
-
cleanup();
tst_exit();
}
--
1.7.4.1
--
Quality Engineer (Kernel) in
Red Hat Software (Beijing) Co., R&D Branch
http://www.cn.redhat.com/
TEL: +86-10-62608150
[-- Attachment #2: 0002-syscalls-acct01-fix-testcases.patch --]
[-- Type: text/plain, Size: 3064 bytes --]
From 5c8d0a1e83c8430a94511a4abc4f086362cd9566 Mon Sep 17 00:00:00 2001
From: Caspar Zhang <czhang@redhat.com>
Date: Fri, 4 Mar 2011 01:01:55 +0800
Subject: [PATCH 2/2] syscalls: acct01: fix testcases
a follow-up fix for http://article.gmane.org/gmane.linux.ltp/13576 .
In fact, it's not a kernel bug of ENOTDIR's failure. ENOTDIR means that
you setup a string as directory in argument, but it is actually a file.
The patch fixes this failure. The result of given path
/tmp/does/not/exist should be expected as ENOENT.
And also, there is a mistake in EPERM case, to restore the permissions,
SAFE_SETUID should be used instead of SAFE_SETGID, else it will never
recover the permissions.
Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
testcases/kernel/syscalls/acct/acct01.c | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c
index 5314f4f..324d423 100644
--- a/testcases/kernel/syscalls/acct/acct01.c
+++ b/testcases/kernel/syscalls/acct/acct01.c
@@ -96,26 +96,36 @@ int main(int argc, char *argv[])
setup();
+ /* EISDIR */
if (acct("/") == -1 && errno == EISDIR)
tst_resm(TPASS, "Failed with EISDIR as expected");
else
tst_brkm(TFAIL|TERRNO, cleanup,
"didn't fail as expected; expected EISDIR");
+ /* EACCES */
if (acct("/dev/null") == -1 && errno == EACCES)
tst_resm(TPASS, "Failed with EACCES as expected");
else
tst_brkm(TFAIL|TERRNO, cleanup,
"didn't fail as expected; expected EACCES");
- if (acct("/tmp/does/not/exist") == -1 && errno == ENOTDIR)
+ /* ENOENT */
+ if (acct("/tmp/does/not/exist") == -1 && errno == ENOENT)
+ tst_resm(TPASS, "Failed with ENOENT as expected");
+ else
+ tst_brkm(TBROK|TERRNO, cleanup,
+ "didn't fail as expected; expected ENOENT");
+
+ /* ENOTDIR */
+ if (acct("/etc/fstab/") == -1 && errno == ENOTDIR)
tst_resm(TPASS, "Failed with ENOTDIR as expected");
else
tst_brkm(TFAIL|TERRNO, cleanup,
"didn't fail as expected; expected ENOTDIR");
+ /* EPERM */
sprintf(tmpbuf, "./%s.%d", TCID, getpid());
-
fd = SAFE_CREAT(cleanup, tmpbuf, 0777);
SAFE_CLOSE(cleanup, fd);
@@ -123,25 +133,17 @@ int main(int argc, char *argv[])
tst_brkm(TBROK|TERRNO, cleanup, "acct failed unexpectedly");
pwent = SAFE_GETPWNAM(cleanup, "nobody");
-
SAFE_SETEUID(cleanup, pwent->pw_uid);
if (acct(tmpbuf) == -1 && errno == EPERM)
- tst_resm(TPASS, "acct failed as expected with EPERM");
+ tst_resm(TPASS, "Failed with EPERM as expected");
else
tst_brkm(TBROK|TERRNO, cleanup,
- "acct didn't fail as expected with EPERM");
-
- SAFE_SETEGID(cleanup, 0);
+ "didn't fail as expected; expected EPERM");
+ SAFE_SETEUID(cleanup, 0);
SAFE_UNLINK(cleanup, tmpbuf);
- if (acct(tmpbuf) == -1 && errno == ENOENT)
- tst_resm(TPASS, "acct failed as expected with ENOENT");
- else
- tst_brkm(TBROK|TERRNO, cleanup,
- "acct didn't fail as expected with ENOENT");
-
cleanup();
tst_exit();
}
--
1.7.4.1
[-- Attachment #3: Type: text/plain, Size: 429 bytes --]
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2011-03-03 17:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-20 13:30 [LTP] [PATCH] Add tst_require_root to acct01 testcase Cristian Greco
2011-01-21 8:28 ` Garrett Cooper
2011-03-03 17:16 ` Caspar Zhang [this message]
2011-03-03 17:42 ` [LTP] [PATCH] syscalls: acct01: fix testcases [was: Re: [PATCH] Add tst_require_root to acct01 testcase.] Cristian Greco
2011-03-04 9:28 ` Garrett Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D6FCCF7.2010101@redhat.com \
--to=czhang@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=yanegomi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox