From 4b01c5a1421df51d340df995a6ec5e132c074d1a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 19 Feb 2014 14:26:52 +0100 Subject: fallocate: fix missing sentinel for is_nul() Signed-off-by: Karel Zak --- sys-utils/fallocate.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sys-utils/fallocate.c') diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index e6dac1993..d8a74bf91 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -130,13 +130,17 @@ static int skip_hole(int fd, off_t *off) return -1; /* no hole */ } -static int is_nul(void const *buf, size_t bufsize) +/* The real buffer size has to be bufsize + sizeof(uintptr_t) */ +static int is_nul(void *buf, size_t bufsize) { typedef uintptr_t word; void const *vp; char const *cbuf = buf, *cp; word const *wp = buf; + /* set sentinel */ + memset((char *) buf + bufsize, '\1', sizeof(word)); + /* Find first nonzero *word*, or the word with the sentinel. */ while (*wp++ == 0) continue; @@ -179,7 +183,8 @@ static void dig_holes(int fd, off_t off, off_t len) if (lseek(fd, off, SEEK_SET) < 0) err(EXIT_FAILURE, _("seek on %s failed"), filename); - buf = xmalloc(bufsz); + /* buffer + extra space for is_nul() sentinel */ + buf = xmalloc(bufsz + sizeof(uintptr_t)); cache_start = off; #if defined(POSIX_FADV_SEQUENTIAL) && defined(HAVE_POSIX_FADVISE) -- cgit v1.2.3-55-g7522