[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 19/21] block/vvfat: Fix compiler warning with gcc 7
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 19/21] block/vvfat: Fix compiler warning with gcc 7 |
Date: |
Tue, 18 Jul 2017 16:18:04 +0200 |
From: Max Reitz <address@hidden>
gcc 7 complains that the sprintf() might write a null byte beyond the
end of the tail buffer. That is wrong, but we can silence it by making
i unsigned (it can never be negative anyway, see the if condition right
before). For some reason, this allows gcc to suddenly accurately
calculate the range of i so we can give the tail[] array the exact size
it needs to have (which is 8 bytes) without gcc complaining.
In addition, let us convert the sprintf() to snprintf(), because that is
always nicer, and add an assertion about the range of the return value
afterwards so we can see that "8 - len" will never be negative and thus
"entry->name + MIN(j, 8 - len)" will never be out of bounds.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vvfat.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index 6b11596..a9e207f 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -549,7 +549,7 @@ static direntry_t *create_short_filename(BDRVVVFATState *s,
const gchar *p, *last_dot = NULL;
gunichar c;
bool lossy_conversion = false;
- char tail[11];
+ char tail[8];
if (!entry) {
return NULL;
@@ -614,7 +614,8 @@ static direntry_t *create_short_filename(BDRVVVFATState *s,
for (i = lossy_conversion ? 1 : 0; i < 999999; i++) {
direntry_t *entry1;
if (i > 0) {
- int len = sprintf(tail, "~%d", i);
+ int len = snprintf(tail, sizeof(tail), "~%u", (unsigned)i);
+ assert(len <= 7);
memcpy(entry->name + MIN(j, 8 - len), tail, len);
}
for (entry1 = array_get(&(s->directory), directory_start);
--
1.8.3.1
- [Qemu-block] [PULL 09/21] block/qapi: Use blk_all_next() for query-block, (continued)
- [Qemu-block] [PULL 09/21] block/qapi: Use blk_all_next() for query-block, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 07/21] block/qapi: Add qdev device name to query-block, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 10/21] block: List anonymous device BBs in query-block, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 11/21] ide: bdrv_attach_dev() for empty CD-ROM, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 12/21] scsi-disk: bdrv_attach_dev() for empty CD-ROM, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 14/21] qemu-iotests: Test unplug of -device without drive, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 16/21] vvfat: add a constant for bootsector name, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 13/21] qemu-iotests: Test 'info block', Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 17/21] vvfat: correctly parse non-ASCII short and long file names, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 15/21] vvfat: add constants for special values of name[0], Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 19/21] block/vvfat: Fix compiler warning with gcc 7,
Kevin Wolf <=
- [Qemu-block] [PULL 20/21] blockdev: move BDRV_O_NO_BACKING option forward, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 18/21] vvfat: initialize memory after allocating it, Kevin Wolf, 2017/07/18
- [Qemu-block] [PULL 21/21] qemu-img: Check for backing image if specified during create, Kevin Wolf, 2017/07/18
- Re: [Qemu-block] [Qemu-devel] [PULL 00/21] Block layer patches, no-reply, 2017/07/18
- Re: [Qemu-block] [Qemu-devel] [PULL 00/21] Block layer patches, no-reply, 2017/07/18
- Re: [Qemu-block] [PULL 00/21] Block layer patches, Peter Maydell, 2017/07/19