Patchwork tests/test-mmap.c: Check mmap() return value before using it

login
register
mail settings
Submitter Peter Maydell
Date April 14, 2011, 1:11 p.m.
Message ID <1302786716-20933-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/91232/
State New
Headers show

Comments

Peter Maydell - April 14, 2011, 1:11 p.m.
Correct the position of a "stop if MAP_FAILED" check in the mmap()
tests, so that if mmap() does fail we print a failure message
rather than segfaulting inside memcpy().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/test-mmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Edgar Iglesias - April 14, 2011, 3:35 p.m.
On Thu, Apr 14, 2011 at 02:11:56PM +0100, Peter Maydell wrote:
> Correct the position of a "stop if MAP_FAILED" check in the mmap()
> tests, so that if mmap() does fail we print a failure message
> rather than segfaulting inside memcpy().
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

I've applied this, thanks.


> ---
>  tests/test-mmap.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/tests/test-mmap.c b/tests/test-mmap.c
> index fcb365f..c578e25 100644
> --- a/tests/test-mmap.c
> +++ b/tests/test-mmap.c
> @@ -164,6 +164,7 @@ void check_aligned_anonymous_unfixed_colliding_mmaps(void)
>  		nlen = pagesize * 8;
>  		p3 = mmap(NULL, nlen, PROT_READ, 
>  			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +		fail_unless (p3 != MAP_FAILED);
>  
>  		/* Check if the mmaped areas collide.  */
>  		if (p3 < p2 
> @@ -174,7 +175,6 @@ void check_aligned_anonymous_unfixed_colliding_mmaps(void)
>  
>  		/* Make sure we get pages aligned with the pagesize. The
>  		   target expects this.  */
> -		fail_unless (p3 != MAP_FAILED);
>  		p = (uintptr_t) p3;
>  		fail_unless ((p & pagemask) == 0);
>  		munmap (p2, pagesize);
> -- 
> 1.7.1
> 
>

Patch

diff --git a/tests/test-mmap.c b/tests/test-mmap.c
index fcb365f..c578e25 100644
--- a/tests/test-mmap.c
+++ b/tests/test-mmap.c
@@ -164,6 +164,7 @@  void check_aligned_anonymous_unfixed_colliding_mmaps(void)
 		nlen = pagesize * 8;
 		p3 = mmap(NULL, nlen, PROT_READ, 
 			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		fail_unless (p3 != MAP_FAILED);
 
 		/* Check if the mmaped areas collide.  */
 		if (p3 < p2 
@@ -174,7 +175,6 @@  void check_aligned_anonymous_unfixed_colliding_mmaps(void)
 
 		/* Make sure we get pages aligned with the pagesize. The
 		   target expects this.  */
-		fail_unless (p3 != MAP_FAILED);
 		p = (uintptr_t) p3;
 		fail_unless ((p & pagemask) == 0);
 		munmap (p2, pagesize);