dm log writes: fix max length used for kstrndup
authorMa Shimiao <mashimiao.fnst@cn.fujitsu.com>
Tue, 12 Dec 2017 09:39:10 +0000 (17:39 +0800)
committerMike Snitzer <snitzer@redhat.com>
Wed, 17 Jan 2018 14:16:16 +0000 (09:16 -0500)
If source string is longer than max, kstrndup will allocate max+1
space.  So make sure the result will not exceed max.

Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-log-writes.c

index 189badbeddaf7bf39ffd97544232aa8ba7a2f9d4..3362d866793b320149bcb7a83b663e1bb68cf927 100644 (file)
@@ -594,7 +594,7 @@ static int log_mark(struct log_writes_c *lc, char *data)
                return -ENOMEM;
        }
 
-       block->data = kstrndup(data, maxsize, GFP_KERNEL);
+       block->data = kstrndup(data, maxsize - 1, GFP_KERNEL);
        if (!block->data) {
                DMERR("Error copying mark data");
                kfree(block);