Don't write outside the requested range master
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 23 Feb 2013 20:30:59 +0000 (15:30 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 23 Feb 2013 20:30:59 +0000 (15:30 -0500)
Ensure we don't spill BUFLEN outside of the requested length.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
test-ssd-write.c

index 5b7c8c4df06f218338d2cd7f96272fbd565fbd09..ea852481e6b94f776cf8df1b983fac7293249311 100644 (file)
@@ -146,13 +146,18 @@ static int rand_write(int fd, size_t len)
        uint64_t valcount;
        int ret;
 
+       if (len < BUFLEN) {
+               fprintf(stderr, "Error: File size needs to be at least %u\n", BUFLEN);
+               exit(EXIT_FAILURE);
+       }
+
        memset(buf, 0, BUFLEN);
 
        for (;;) {
                if (len > UINT32_MAX) {
-                       offset = (((size_t) rand() << 32) + (size_t) rand()) % len;
+                       offset = (((size_t) rand() << 32) + (size_t) rand()) % (len - BUFLEN);
                } else {
-                       offset = rand() % len;
+                       offset = rand() % (len - BUFLEN);
                }
 
                if ((offset >= validate_offset &&
This page took 0.033199 seconds and 4 git commands to generate.