[PATCH 2/9] UML - Fix off-by-one bug in VM file creation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix an off-by-one bug in temp file creation.  Seeking to the desired
length and writing a byte resulted in the file being one byte longer
than expected.

Signed-off-by: Jeff Dike <[email protected]>

Index: linux-2.6.17/arch/um/os-Linux/mem.c
===================================================================
--- linux-2.6.17.orig/arch/um/os-Linux/mem.c	2006-06-29 10:42:11.000000000 -0400
+++ linux-2.6.17/arch/um/os-Linux/mem.c	2006-06-29 11:42:23.000000000 -0400
@@ -210,8 +210,11 @@ int create_tmp_file(unsigned long long l
 		exit(1);
 	}
 
-        if (lseek64(fd, len, SEEK_SET) < 0) {
- 		perror("os_seek_file");
+	/* Seek to len - 1 because writing a character there will
+	 * increase the file size by one byte, to the desired length.
+	 */
+	if (lseek64(fd, len - 1, SEEK_SET) < 0) {
+		perror("os_seek_file");
 		exit(1);
 	}
 

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux