From: Peng H. <pe...@cn...> - 2011-04-01 09:43:42
|
Mike Frysinger said the following on 2011-3-30 15:49: > On Wed, Mar 30, 2011 at 3:46 AM, Peng Haitao wrote: >> +char *buf = "abcdefghijklmnopqrstuvwxyz"; > > if you used: > char buf[] = .... > >> - SAFE_MUNMAP(NULL, addr, sizeof(file1)); >> + SAFE_MUNMAP(NULL, addr, strlen(buf)); > > you could use sizeof(buf) here > > and it'd be slightly less overhead Thanks for your comment. So, what about the following one? ----------------------------------------------------------------------------- When test mprotect02 in RHEL6.0 x86_64, Segmentation fault. The third argument of SAFE_MUNMAP() is wrong in function cleanup(), it should be the length of SAFE_MMAP(). If the first SAFE_MUNMAP() is success, the second SAFE_MUNMAP() should not be invoked. Signed-off-by: Peng Haitao <pe...@cn...> --- testcases/kernel/syscalls/mprotect/mprotect02.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/testcases/kernel/syscalls/mprotect/mprotect02.c b/testcases/kernel/syscalls/mprotect/mprotect02.c index 1a2720c..97250c5 100644 --- a/testcases/kernel/syscalls/mprotect/mprotect02.c +++ b/testcases/kernel/syscalls/mprotect/mprotect02.c @@ -69,6 +69,7 @@ int fd, status; char file1[BUFSIZ]; char *addr = MAP_FAILED; +char buf[] = "abcdefghijklmnopqrstuvwxyz"; #ifndef UCLINUX @@ -76,7 +77,6 @@ int main(int ac, char **av) { int lc; char *msg; - char *buf = "abcdefghijklmnopqrstuvwxyz"; int bytes_to_write, fd, num_bytes; pid_t pid; @@ -106,7 +106,7 @@ int main(int ac, char **av) } while (0 < num_bytes); /* mmap the PAGESIZE bytes as read only. */ - addr = SAFE_MMAP(cleanup, 0, strlen(buf), PROT_READ, + addr = SAFE_MMAP(cleanup, 0, sizeof(buf), PROT_READ, MAP_SHARED, fd, 0); if ((pid = FORK_OR_VFORK()) == -1) @@ -129,7 +129,7 @@ int main(int ac, char **av) status); /* Change the protection to WRITE. */ - TEST(mprotect(addr, strlen(buf), PROT_WRITE)); + TEST(mprotect(addr, sizeof(buf), PROT_WRITE)); if (TEST_RETURN != -1) { @@ -163,7 +163,8 @@ int main(int ac, char **av) continue; } - SAFE_MUNMAP(cleanup, addr, strlen(buf)); + SAFE_MUNMAP(cleanup, addr, sizeof(buf)); + addr = MAP_FAILED; SAFE_CLOSE(cleanup, fd); @@ -199,7 +200,7 @@ static void cleanup() TEST_CLEANUP; if (addr != MAP_FAILED) { - SAFE_MUNMAP(NULL, addr, sizeof(file1)); + SAFE_MUNMAP(NULL, addr, sizeof(buf)); SAFE_CLOSE(NULL, fd); } -- 1.7.1 -- Best Regards, Peng Haitao |