summaryrefslogtreecommitdiffstats
path: root/sys-utils/fallocate.c
diff options
context:
space:
mode:
authorKarel Zak2014-02-19 14:26:52 +0100
committerKarel Zak2014-02-19 14:26:52 +0100
commit4b01c5a1421df51d340df995a6ec5e132c074d1a (patch)
tree7c91b190042d54ceff937f93f4eab85a11b6ba40 /sys-utils/fallocate.c
parentlibblkid: add extra checks to XFS prober (diff)
downloadkernel-qcow2-util-linux-4b01c5a1421df51d340df995a6ec5e132c074d1a.tar.gz
kernel-qcow2-util-linux-4b01c5a1421df51d340df995a6ec5e132c074d1a.tar.xz
kernel-qcow2-util-linux-4b01c5a1421df51d340df995a6ec5e132c074d1a.zip
fallocate: fix missing sentinel for is_nul()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/fallocate.c')
-rw-r--r--sys-utils/fallocate.c9
1 files changed, 7 insertions, 2 deletions
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)