[libvirt PATCH 0/3] Fix null string specifiers detected by GCC

Each of the following tripped the -Wformat-overflow warning in GCC 11. The fixes all seemed pretty obvious based on the context. Apologies for any formatting or other mistakes, this is my first time submitting libvirt patches and using git publish. Scott Davis (3): qemu: fix null string specifier argument in qemuDomainBlockJobAbort remote: fix null string specifier argument in remoteProbeSessionDriverFromBinary vircgroupv1: fix null string specifier argument in virCgroupV1ValidatePlacement src/qemu/qemu_driver.c | 8 ++++---- src/remote/remote_sockets.c | 2 +- src/util/vircgroupv1.c | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) -- 2.25.1

Detected by gcc 11 -Wformat-overflow: ../../src/qemu/qemu_driver.c: In function ‘qemuDomainBlockJobAbort’: ../../src/util/virerror.h:176:5: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 176 | virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 | __FUNCTION__, __LINE__, __VA_ARGS__) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/qemu/qemu_driver.c:14475:17: note: in expansion of macro ‘virReportError’ 14475 | virReportError(VIR_ERR_OPERATION_FAILED, | ^~~~~~~~~~~~~~ ../../src/qemu/qemu_driver.c:14476:73: note: format string is defined here 14476 | _("block job '%s' failed while pivoting: %s"), | ^~ Signed-off-by: Scott Davis <scott.davis@starlab.io> --- src/qemu/qemu_driver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6631edb9d6..d3ba74c14a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14581,13 +14581,13 @@ qemuDomainBlockJobAbort(virDomainPtr dom, if (pivot && job->state == QEMU_BLOCKJOB_STATE_FAILED) { if (job->errmsg) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("block job '%s' failed while pivoting"), - job->name); - } else { virReportError(VIR_ERR_OPERATION_FAILED, _("block job '%s' failed while pivoting: %s"), job->name, job->errmsg); + } else { + virReportError(VIR_ERR_OPERATION_FAILED, + _("block job '%s' failed while pivoting"), + job->name); } ret = -1; -- 2.25.1

Detected by gcc 11 -Wformat-overflow: ../src/remote/remote_sockets.c: In function ‘remoteProbeSessionDriverFromBinary’: ../src/util/virlog.h:79:5: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 79 | virLogMessage(src, VIR_LOG_DEBUG, filename, linenr, funcname, NULL, __VA_ARGS__) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/util/virlog.h:88:5: note: in expansion of macro ‘VIR_DEBUG_INT’ 88 | VIR_DEBUG_INT(&virLogSelf, __FILE__, __LINE__, __func__, __VA_ARGS__) | ^~~~~~~~~~~~~ ../src/remote/remote_sockets.c:187:9: note: in expansion of macro ‘VIR_DEBUG’ 187 | VIR_DEBUG("Probing driver '%s' via daemon %s", drivers[i], daemonpath); | ^~~~~~~~~ ../src/remote/remote_sockets.c:187:51: note: format string is defined here 187 | VIR_DEBUG("Probing driver '%s' via daemon %s", drivers[i], daemonpath); | ^~ Signed-off-by: Scott Davis <scott.davis@starlab.io> --- src/remote/remote_sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c index c315b24d30..69e6c1e5b8 100644 --- a/src/remote/remote_sockets.c +++ b/src/remote/remote_sockets.c @@ -184,7 +184,7 @@ remoteProbeSessionDriverFromBinary(char **driver) g_autofree char *daemonpath = NULL; daemonname = g_strdup_printf("virt%sd", drivers[i]); - VIR_DEBUG("Probing driver '%s' via daemon %s", drivers[i], daemonpath); + VIR_DEBUG("Probing driver '%s' via daemon %s", drivers[i], daemonname); if (!(daemonpath = virFileFindResource(daemonname, abs_top_builddir "/src", -- 2.25.1

Detected by gcc 11 -Wformat-overflow: ../../src/util/vircgroupv1.c: In function ‘virCgroupV1ValidatePlacement’: ../../src/util/virerror.h:176:5: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 176 | virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 | __FUNCTION__, __LINE__, __VA_ARGS__) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/util/vircgroupv1.c:411:13: note: in expansion of macro ‘virReportError’ 411 | virReportError(VIR_ERR_INTERNAL_ERROR, | ^~~~~~~~~~~~~~ ../../src/util/vircgroupv1.c:412:80: note: format string is defined here 412 | _("Could not find placement for v1 controller %s at %s"), | ^~ Signed-off-by: Scott Davis <scott.davis@starlab.io> --- src/util/vircgroupv1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 96f36c3b4d..cbee08e931 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -409,9 +409,8 @@ virCgroupV1ValidatePlacement(virCgroup *group, if (!group->legacy[i].placement) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find placement for v1 controller %s at %s"), - virCgroupV1ControllerTypeToString(i), - group->legacy[i].placement); + _("Could not find placement for v1 controller %s"), + virCgroupV1ControllerTypeToString(i)); return -1; } -- 2.25.1

On a Wednesday in 2022, Scott Davis wrote:
Each of the following tripped the -Wformat-overflow warning in GCC 11. The fixes all seemed pretty obvious based on the context.
Apologies for any formatting or other mistakes, this is my first time submitting libvirt patches and using git publish.
The author (in the From field in the email) has your gmail address while the sign-off has your starlab address. If you're okay with me changing the author to match the signoff address, I can push it after the pipeline succeeds: https://gitlab.com/janotomko/libvirt/-/pipelines/548600566
Scott Davis (3): qemu: fix null string specifier argument in qemuDomainBlockJobAbort remote: fix null string specifier argument in remoteProbeSessionDriverFromBinary vircgroupv1: fix null string specifier argument in virCgroupV1ValidatePlacement
src/qemu/qemu_driver.c | 8 ++++---- src/remote/remote_sockets.c | 2 +- src/util/vircgroupv1.c | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On 5/26/22, 4:20 AM, Ján Tomko wrote:
The author (in the From field in the email) has your gmail address while the sign-off has your starlab address.
If you're okay with me changing the author to match the signoff address, I can push it after the pipeline succeeds: https://gitlab.com/janotomko/libvirt/-/pipelines/548600566
That is fine. Sorry, I've not been able to get my corporate account to work with git send-email. -Scott Davis

On a Thursday in 2022, Scott Davis wrote:
On 5/26/22, 4:20 AM, Ján Tomko wrote:
The author (in the From field in the email) has your gmail address while the sign-off has your starlab address.
If you're okay with me changing the author to match the signoff address, I can push it after the pipeline succeeds: https://gitlab.com/janotomko/libvirt/-/pipelines/548600566
That is fine. Sorry, I've not been able to get my corporate account to work with git send-email.
That's increasingly common with corporate accounts these days. And one of the reasons why all the other repos in the libvirt group already use GitLab's merge requests. I've pushed the patches now, thank you for the contribution! Jano
-Scott Davis
participants (3)
-
Ján Tomko
-
Scott Davis
-
Scott Davis