From c2b7a4bb30008dc256d63802e02b6fb950958443 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Fri, 30 Jun 2006 01:55:54 -0700 Subject: [PATCH] uml: fix /proc/mounts parsing boundary condition When parsing /proc/mounts looking for a tmpfs mount on /dev/shm, if a string that we are looking for if split across reads, then it won't be recognized. Fix this by refilling the buffer whenever we advance the cursor. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/os-Linux/mem.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'arch/um/os-Linux/mem.c') diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index c6432e72924..d24d1a96052 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -55,7 +55,7 @@ static void __init find_tempdir(void) */ static int next(int fd, char *buf, int size, char c) { - int n; + int n, len; char *ptr; while((ptr = strchr(buf, c)) == NULL){ @@ -69,7 +69,17 @@ static int next(int fd, char *buf, int size, char c) } ptr++; - memmove(buf, ptr, strlen(ptr) + 1); + len = strlen(ptr); + memmove(buf, ptr, len + 1); + + /* Refill the buffer so that if there's a partial string that we care + * about, it will be completed, and we can recognize it. + */ + n = read(fd, &buf[len], size - len - 1); + if(n < 0) + return -errno; + + buf[len + n] = '\0'; return 1; } -- cgit v1.2.3-70-g09d2 From 190f4939222b8c07cd62a20e1ce0c7a97fffde99 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Fri, 30 Jun 2006 01:55:55 -0700 Subject: [PATCH] uml: fix off-by-one bug in VM file creation 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 Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/os-Linux/mem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'arch/um/os-Linux/mem.c') diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index d24d1a96052..560c8063c77 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -210,8 +210,11 @@ int create_tmp_file(unsigned long long len) 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); } -- cgit v1.2.3-70-g09d2