]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
fstests: aiodio_sparse2.c, fix compiler warning buffer overflow
authorAnand Jain <anand.jain@oracle.com>
Sun, 29 Jan 2023 02:42:33 +0000 (10:42 +0800)
committerZorro Lang <zlang@kernel.org>
Fri, 3 Feb 2023 18:06:30 +0000 (02:06 +0800)
The warning is due to 'strncpy' with a maximum number of characters
equal to the destination buffer size, without space for null termination.

aiodio_sparse2.c: In function 'main':
aiodio_sparse2.c:404:9: warning: 'strncpy' specified bound 4096 equals destination size [-Wstringop-truncation]
  404 |         strncpy(filename, argv[argc-1], PATH_MAX);

However, PATH_MAX is including null termination at the end. Anyways, fix
warning by setting NULL.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
src/aio-dio-regress/aiodio_sparse2.c

index 51ede5bb6c8b83a3a96b186d9ad5c5d1f9fb7e20..685e3b9dce48ceaa5aea74f29d25c4a776d8e03f 100644 (file)
@@ -402,6 +402,7 @@ int main(int argc, char **argv)
        }
 
        strncpy(filename, argv[argc-1], PATH_MAX);
+       filename[PATH_MAX - 1] = '\0';
 
        if (alignment == 0)
                alignment = get_logical_block_size(filename);