xfs
[Top] [All Lists]

[PATCH] xfs: avoid null *src in memcpy call in xlog_write

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfs: avoid null *src in memcpy call in xlog_write
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Wed, 7 Oct 2015 11:33:43 -0500
Delivered-to: xfs@xxxxxxxxxxx
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
The gcc undefined behavior sanitizer caught this; surely
any sane memcpy implementation will no-op if size == 0,
but behavior with a *src of NULL is technically undefined
(declared nonnull), so avoid it here.

We are actually in this situation frequently via
xlog_commit_record(), because:

        struct xfs_log_iovec reg = {
                .i_addr = NULL,
                .i_len = 0,
                .i_type = XLOG_REG_TYPE_COMMIT,
        };

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 4012523..8897fd1 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -2424,7 +2424,10 @@ xlog_write(
 
                        /* copy region */
                        ASSERT(copy_len >= 0);
-                       memcpy(ptr, reg->i_addr + copy_off, copy_len);
+                       ASSERT(reg->i_addr + copy_off > 0 || copy_len == 0);
+                       /* size == 0 is ok, but *src == NULL is undefined */
+                       if (reg->i_addr + copy_off)
+                               memcpy(ptr, reg->i_addr + copy_off, copy_len);
                        xlog_write_adv_cnt(&ptr, &len, &log_offset, copy_len);
 
                        copy_len += start_rec_copy + sizeof(xlog_op_header_t);

<Prev in Thread] Current Thread [Next in Thread>