Patchwork [3/7] linux-user: Use guest_start_len_valid in msync.

login
register
mail settings
Submitter Richard Henderson
Date March 30, 2010, 6:49 p.m.
Message ID <d01202b3d47a94149be465950ebe9b59413beffb.1270488612.git.rth@twiddle.net>
Download mbox | patch
Permalink /patch/49413/
State New
Headers show

Comments

Richard Henderson - March 30, 2010, 6:49 p.m.
Make sure to properly handle len = 0 first.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 linux-user/mmap.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

Patch

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 46923c7..f4d44a8 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -706,15 +706,18 @@  int target_msync(abi_ulong start, abi_ulong len, int flags)
 {
     abi_ulong end;
 
-    if (start & ~TARGET_PAGE_MASK)
+    if (start & ~TARGET_PAGE_MASK) {
         return -EINVAL;
+    }
+    if (len == 0) {
+        return 0;
+    }
     len = TARGET_PAGE_ALIGN(len);
-    end = start + len;
-    if (end < start)
+    if (!guest_start_len_valid(start, len)) {
         return -EINVAL;
-    if (end == start)
-        return 0;
+    }
 
+    end = start + len;
     start &= qemu_host_page_mask;
     return msync(g2h(start), end - start, flags);
 }