mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
GCC 7: Allocate sufficient space for sprintf output.
GCC 7.0.1 can determine if there is likely to be sufficient space in
the output buffer when using sprintf/snprintf, based on the format
string.
The errors were all either of this form:
bindtests.c:717:29: error: '%zu' directive output may be truncated writing between 1 and 19 bytes into a region of size 16 [-Werror=format-truncation=]
snprintf (strs[i], 16, "%zu", i);
^~~
bindtests.c:717:28: note: directive argument in the range [0, 2305843009213693951]
snprintf (strs[i], 16, "%zu", i);
^~~~~
or this form:
sync.c: In function 'fsync_devices':
sync.c:108:50: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 251 [-Werror=format-truncation=]
snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
^~
Fixed by converting these into dynamic allocation, or making the
output buffer larger, whichever was easier.
There is a gnulib macro we can use to make this simpler for integers.
It requires a new gnulib module (intprops), but it turns out that we
were already pulling that in through dependencies, so the change to
bootstrap is a no-op. (thanks: Dan Berrange)
This commit is contained in:
10
daemon/9p.c
10
daemon/9p.c
@@ -71,9 +71,13 @@ do_list_9p (void)
|
||||
if (d == NULL) break;
|
||||
|
||||
if (STRPREFIX (d->d_name, "virtio")) {
|
||||
char mount_tag_path[256];
|
||||
snprintf (mount_tag_path, sizeof mount_tag_path,
|
||||
BUS_PATH "/%s/mount_tag", d->d_name);
|
||||
CLEANUP_FREE char *mount_tag_path = NULL;
|
||||
if (asprintf (&mount_tag_path, BUS_PATH "/%s/mount_tag",
|
||||
d->d_name) == -1) {
|
||||
reply_with_perror ("asprintf");
|
||||
closedir (dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* A bit unclear, but it looks like the virtio transport allows
|
||||
* the mount tag length to be unlimited (or up to 65536 bytes).
|
||||
|
||||
Reference in New Issue
Block a user