Add format attributes and fix format strings
Subsystems (2)
v3 cover Add format attributes and fix format strings
v3:
- Fix description for patch 3
- Add patches 5 and 6
The patches 3 and 5 still need reviews!
[PATCH v3 for-7.2 1/6] libvhost-user: Fix wrong type of argument to [PATCH v3 for-7.2 2/6] libvhost-user: Fix format strings [PATCH v3 for-7.2 3/6] libvhost-user: Fix two more format strings [PATCH v3 for-7.2 4/6] libvhost-user: Add format attribute to local [PATCH v3 for-7.2 5/6] MAINTAINERS: Add subprojects/libvhost-user to [PATCH v3 for-7.2 6/6] Add G_GNUC_PRINTF to function
PATCH v3 1/6 libvhost-user: Fix wrong type of argument to formatting function (reported by LGTM)
Message-Id: <[email protected]>
--- subprojects/libvhost-user/libvhost-user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.c +1 -1
@@ -651,7 +651,7 @@ generate_faults(VuDev *dev) {if (ioctl (dev->postcopy_ufd,UFFDIO_REGISTER , ®_struct)) { vu_panic(dev, "%s: Failed to userfault region %d " - "@%p + size:%zx offset: %zx: (ufd=%d)%s\n", + "@%" PRIx64 " + size:%zx offset: %zx: (ufd=%d)%s\n", __func__, i, dev_region->mmap_addr, dev_region->size, dev_region->mmap_offset,
Signature · 1 line
2.35.1
PATCH v3 2/6 libvhost-user: Fix format strings
In reply to Stefan Weil viaMessage-Id: <[email protected]>
--- subprojects/libvhost-user/libvhost-user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
subprojects/libvhost-user/libvhost-user.c +2 -2
@@ -700,7 +700,7 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {if (vmsg->size <VHOST_USER_MEM_REG_SIZE ) {close (vmsg->fds[0 ]);vu_panic (dev,"VHOST_USER_ADD_MEM_REG requires a message size of at " -"least %d bytes and only %d bytes were received" , +"least %zu bytes and only %d bytes were received" ,VHOST_USER_MEM_REG_SIZE , vmsg->size);return false; }
@@ -826,7 +826,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {if (vmsg->size <VHOST_USER_MEM_REG_SIZE ) {vmsg_close_fds (vmsg);vu_panic (dev,"VHOST_USER_REM_MEM_REG requires a message size of at " -"least %d bytes and only %d bytes were received" , +"least %zu bytes and only %d bytes were received" ,VHOST_USER_MEM_REG_SIZE , vmsg->size);return false; }
Signature · 1 line
2.35.1
PATCH v3 3/6 libvhost-user: Fix two more format strings
In reply to Stefan Weil viaThis fix is required for 32 bit hosts. The bug was detected by CI for arm-linux, but is also relevant for i386-linux.
--- subprojects/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.c +2 -1
@@ -651,7 +651,8 @@ generate_faults(VuDev *dev) {if (ioctl (dev->postcopy_ufd,UFFDIO_REGISTER , ®_struct)) { vu_panic(dev, "%s: Failed to userfault region %d " - "@%" PRIx64 " + size:%zx offset: %zx: (ufd=%d)%s\n", + "@%" PRIx64 " + size:%" PRIx64 " offset: %" PRIx64 + ": (ufd=%d)%s\n", __func__, i, dev_region->mmap_addr, dev_region->size, dev_region->mmap_offset,
Signature · 1 line
2.35.1
Re: [PATCH v3 for-7.2 3/6] libvhost-user: Fix two more format strings
Quoted 9 lines · Stefan Weil
This fix is required for 32 bit hosts. The bug was detected by CI for arm-linux, but is also relevant for i386-linux.
Reported-by Stefan Hajnoczi <[email protected]>Signed-off-by Stefan Weil <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 18 lines
subprojects/libvhost-user/libvhost-user.c +2
-2@@ -651,7 +651,8 @@ generate_faults(VuDev *dev) {if (ioctl (dev->postcopy_ufd,UFFDIO_REGISTER , ®_struct)) { vu_panic(dev, "%s: Failed to userfault region %d " - "@%" PRIx64 " + size:%zx offset: %zx: (ufd=%d)%s\n", + "@%" PRIx64 " + size:%" PRIx64 " offset: %" PRIx64 + ": (ufd=%d)%s\n", __func__, i, dev_region->mmap_addr, dev_region->size, dev_region->mmap_offset, --2.35.1
PATCH v3 4/6 libvhost-user: Add format attribute to local function vu_panic
In reply to Stefan Weil viaMessage-Id: <[email protected]>
--- subprojects/libvhost-user/libvhost-user.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.c +12 -1
@@ -45,6 +45,17 @@#include "libvhost-user.h" /* usually provided by GLib */ +#if __GNUC__ >2 || (__GNUC__ ==2 && __GNUC_MINOR__ >4 ) +#if !defined(__clang__) && (__GNUC__ ==4 && __GNUC_MINOR__ ==4 ) +#define G_GNUC_PRINTF (format_idx, arg_idx) \ + __attribute__((__format__(gnu_printf, format_idx, arg_idx))) +#else +#define G_GNUC_PRINTF (format_idx, arg_idx) \ + __attribute__((__format__(__printf__, format_idx, arg_idx))) +#endif +#else /* !__GNUC__ */ +#define G_GNUC_PRINTF (format_idx, arg_idx) +#endif /* !__GNUC__ */ #ifndef MIN #define MIN (x, y) ({ \ typeof(x) _min1 = (x); \
@@ -151,7 +162,7 @@ vu_request_to_string(unsigned int req) } } -static void +static void G_GNUC_PRINTF(2, 3) vu_panic(VuDev *dev, const char *msg, ...) {char *buf =NULL ;
Signature · 1 line
2.35.1
Re: [PATCH v3 for-7.2 4/6] libvhost-user: Add format attribute to local function vu_panic
Quoted 8 lines · Stefan Weil
Signed-off-by Stefan Weil <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
Signed-off-by Laurent Vivier <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
I would rather not merge something that can cause new build failures this late in the release cycle.
If you respin, please make this a separate 8.0 patch.
Quoted 34 lines
subprojects/libvhost-user/libvhost-user.c +12
-2@@ -45,6 +45,17 @@#include "libvhost-user.h" /* usually provided by GLib */ +#if __GNUC__ >2 || (__GNUC__ ==2 && __GNUC_MINOR__ >4 ) +#if !defined(__clang__) && (__GNUC__ ==4 && __GNUC_MINOR__ ==4 ) +#define G_GNUC_PRINTF (format_idx, arg_idx) \ + __attribute__((__format__(gnu_printf, format_idx, arg_idx))) +#else +#define G_GNUC_PRINTF (format_idx, arg_idx) \ + __attribute__((__format__(__printf__, format_idx, arg_idx))) +#endif +#else /* !__GNUC__ */ +#define G_GNUC_PRINTF (format_idx, arg_idx) +#endif /* !__GNUC__ */ #ifndef MIN #define MIN (x, y) ({ \ typeof(x) _min1 = (x); \@@ -151,7 +162,7 @@ vu_request_to_string(unsigned int req) } } -static void +static void G_GNUC_PRINTF(2, 3) vu_panic(VuDev *dev, const char *msg, ...) {char *buf =NULL ; --2.35.1
Re: [PATCH v3 for-7.2 4/6] libvhost-user: Add format attribute to local function vu_panic
Am 27.11.22 um 19:14 schrieb Stefan Hajnoczi:
Quoted 8 lines · Stefan Weil
Quoted 7 lines
Signed-off-by Stefan Weil <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
Signed-off-by Laurent Vivier <[email protected]>--- subprojects/libvhost-user/libvhost-user.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Quoted 4 lines
I would rather not merge something that can cause new build failures this late in the release cycle.
If you respin, please make this a separate 8.0 patch.
It would only cause a build failure if there remained more format bugs, but the last ones were fixed in patch 3. I tested a build for 32 bit ARM (which previously failed without patch 3), and it works now.
But you are right, patch 4 is not release critical as it is not a bug fix (like the other ones), so not including it in 7.2 might be an option.
Stefan
PATCH v3 5/6 MAINTAINERS: Add subprojects/libvhost-user to section "vhost"
In reply to Stefan Weil via--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -2005,6 +2005,7 @@ F: docs/interop/vhost-user.rst F: contrib/vhost-user-*/ F: backends/vhost-user.c F: include/sysemu/vhost-user-backend.h +F: subprojects/libvhost-user/ virtio M: Michael S. Tsirkin <[email protected]>
Signature · 1 line
2.35.1
Re: [PATCH v3 for-7.2 5/6] MAINTAINERS: Add subprojects/libvhost-user to section "vhost"
Quoted 11 lines · Stefan Weil
Signed-off-by Stefan Weil <[email protected]>--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)MAINTAINERS +0
-0
MAINTAINERS F: docs/interop/vhost-user.rst · line 2008
Quoted 4 lines
MAINTAINERS +1
-0@@ -2005,6 +2005,7 @@ F: docs/interop/vhost-user.rst F: contrib/vhost-user-*/ F: backends/vhost-user.c F: include/sysemu/vhost-user-backend.h +F: subprojects/libvhost-user/
Requires agreement from Michael. Also including Marc-André who originally created libvhost-user.
Stefan
Re: [PATCH v3 for-7.2 5/6] MAINTAINERS: Add subprojects/libvhost-user to section "vhost"
Quoted 8 lines · Stefan Hajnoczi
Quoted 6 lines · Stefan Weil
Signed-off-by Stefan Weil <[email protected]>--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
MAINTAINERS F: docs/interop/vhost-user.rst · line 2008
Quoted 9 lines
MAINTAINERS +1
-0@@ -2005,6 +2005,7 @@ F: docs/interop/vhost-user.rst F: contrib/vhost-user-*/ F: backends/vhost-user.c F: include/sysemu/vhost-user-backend.h +F: subprojects/libvhost-user/Requires agreement from Michael. Also including Marc-André who originally created libvhost-user.
Stefan showed me the email where Michael agreed:
https://lore.kernel.org/qemu-devel/[email protected]/
Stefan
PATCH v3 6/6 Add G_GNUC_PRINTF to function qemu_set_info_str and fix related issues
In reply to Stefan Weil viaWith the G_GNUC_PRINTF function attribute the compiler detects two potential insecure format strings:
../../../net/stream.c:248:31: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
qemu_set_info_str(&s->nc, uri);
^~~
../../../net/stream.c:322:31: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
qemu_set_info_str(&s->nc, uri);
^~~There are also two other warnings:
../../../net/socket.c:182:35: warning: zero-length gnu_printf format string [-Wformat-zero-length]
182 | qemu_set_info_str(&s->nc, "");
| ^~../../../net/stream.c:170:35: warning: zero-length gnu_printf format string [-Wformat-zero-length]
170 | qemu_set_info_str(&s->nc, "");
--- include/net/net.h | 3 ++- net/socket.c | 2 +- net/stream.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-)
include/net/net.h +2 -1
@@ -177,7 +177,8 @@ ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,void qemu_purge_queued_packets (NetClientState *nc);void qemu_flush_queued_packets (NetClientState *nc);void qemu_flush_or_purge_queued_packets (NetClientState *nc,bool purge); -void qemu_set_info_str (NetClientState *nc,const char *fmt, ...); +void qemu_set_info_str(NetClientState *nc, + const char *fmt, ...) G_GNUC_PRINTF(2, 3);void qemu_format_nic_info_str (NetClientState *nc,uint8_t macaddr[6 ]);bool qemu_has_ufo (NetClientState *nc);bool qemu_has_vnet_hdr (NetClientState *nc);
net/socket.c +1 -1
@@ -179,7 +179,7 @@ static void net_socket_send(void *opaque) s->fd =-1 ;net_socket_rs_init (&s->rs, net_socket_rs_finalize, false); s->nc.link_down = true; -qemu_set_info_str (&s->nc,"" ); +qemu_set_info_str (&s->nc,"%s" ,"" );return ; }
net/stream.c +3 -3
@@ -167,7 +167,7 @@ static gboolean net_stream_send(QIOChannel *ioc,net_socket_rs_init (&s->rs, net_stream_rs_finalize, false); s->nc.link_down = true; -qemu_set_info_str (&s->nc,"" ); +qemu_set_info_str (&s->nc,"%s" ,"" );qapi_event_send_netdev_stream_disconnected (s->nc.name);
@@ -245,7 +245,7 @@ static void net_stream_listen(QIONetListener *listener, }g_assert (addr !=NULL ); uri =socket_uri (addr); -qemu_set_info_str (&s->nc, uri); +qemu_set_info_str (&s->nc,"%s" , uri);g_free (uri);qapi_event_send_netdev_stream_connected (s->nc.name, addr);qapi_free_SocketAddress (addr);
@@ -319,7 +319,7 @@ static void net_stream_client_connected(QIOTask *task, gpointer opaque) addr =qio_channel_socket_get_remote_address (sioc,NULL );g_assert (addr !=NULL ); uri =socket_uri (addr); -qemu_set_info_str (&s->nc, uri); +qemu_set_info_str (&s->nc,"%s" , uri);g_free (uri); ret =qemu_socket_try_set_nonblock (sioc->fd);
Signature · 1 line
2.35.1
We need to wait for Michael to agree to maintainership in patch 5. If we run out of time I suggest splitting out patch 5.
Am 27.11.22 um 19:23 schrieb Stefan Hajnoczi:
Quoted 4 lines
We need to wait for Michael to agree to maintainership in patch 5. If we run out of time I suggest splitting out patch 5.
Reviewed-by Stefan Hajnoczi<[email protected]>
Citing Michael from a v2 email: "pls do".
Stefan
Quoted 7 lines
Hello Michael,
I just noticed that
MAINTAINERShas no entry for the files in subprojects/libvhost-user, so I did not cc you in my previous e-mails. Should that directory be added to the "vhost" section"?Stefan
pls do
Quoted 16 lines · Stefan Weil
Am 27.11.22 um 19:23 schrieb Stefan Hajnoczi:
We need to wait for Michael to agree to maintainership in patch 5. If we run out of time I suggest splitting out patch 5.
Reviewed-by Stefan Hajnoczi <[email protected]>Citing Michael from a v2 email: "pls do".
Stefan
Hello Michael,
Quoted 7 lines
I just noticed that
MAINTAINERShas no entry for the files in subprojects/libvhost-user, so I did not cc you in my previous e-mails. Should that directory be added to the "vhost" section"?Stefan
pls do
Perfect, thank you! I have added a reference to that email in the commit description.
This series is running through CI now and will be merged upon success later today.
Thanks,
Stefan
Quoted 5 lines · Stefan Weil
v3:
- Fix description for patch 3
- Add patches 5 and 6The patches 3 and 5 still need reviews!
Series:
Stefan you said you want to merge this?
Quoted 6 lines
[PATCH v3 for-7.2 1/6] libvhost-user: Fix wrong type of argument to [PATCH v3 for-7.2 2/6] libvhost-user: Fix format strings [PATCH v3 for-7.2 3/6] libvhost-user: Fix two more format strings [PATCH v3 for-7.2 4/6] libvhost-user: Add format attribute to local [PATCH v3 for-7.2 5/6]
MAINTAINERS: Add subprojects/libvhost-user to [PATCH v3 for-7.2 6/6] AddG_GNUC_PRINTFto function
Quoted 5 lines · On Mon, Nov 28, 2022, 05:29 Michael S. Tsirkin <[email protected]> wrote:
Quoted 4 lines · Stefan Weil
v3:
- Fix description for patch 3
- Add patches 5 and 6
Quoted 7 lines
Quoted 1 line
The patches 3 and 5 still need reviews!
Series:
Reviewed-by Michael S. Tsirkin <[email protected]>Stefan you said you want to merge this?
Yes.
Stefan
Quoted 1 line
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/7.2 for any user-visible changes.