[PATCH 0/2] fix crash on invalid construction of a gvariant

Peter Krempa (2): virSystemdCreateMachine: Use proper format string for uint64_t when constructing gvariant virsystemdtest: Call at least one virSystemdCreateMachine with 'maxthreads' > 0 src/util/virsystemd.c | 5 +++-- tests/virsystemdtest.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) -- 2.29.2

g_variant_new_parsed uses '%t' for a uint64_t rather than printf-like %llu. Additionally ensure that the passed value is a uint64_t since the argument used is a 'unsigned int'. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1937287 Fixes: bf5f2ed09c2 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virsystemd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index c109324e96..c22f2df866 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -519,11 +519,12 @@ int virSystemdCreateMachine(const char *name, } if (maxthreads > 0) { + uint64_t max = maxthreads; + if (!(scopename = virSystemdMakeScopeName(name, drivername, false))) return -1; - gprops = g_variant_new_parsed("[('TasksMax', <%llu>)]", - (uint64_t)maxthreads); + gprops = g_variant_new_parsed("[('TasksMax', <%t>)]", max); message = g_variant_new("(sb@a(sv))", scopename, -- 2.29.2

There was a bug in the code adding TasksMax property. It remained undetected because all tests used '0' for @maxthreads. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virsystemdtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index b48cdb950c..c082b95732 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -313,7 +313,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_UNUSED) 123, true, nnicindexes, nicindexes, - "highpriority.slice", 0) < 0) { + "highpriority.slice", 2) < 0) { fprintf(stderr, "%s", "Failed to create LXC machine\n"); return -1; } -- 2.29.2

On Wed, Mar 10, 2021 at 02:40:34PM +0100, Peter Krempa wrote:
Peter Krempa (2): virSystemdCreateMachine: Use proper format string for uint64_t when constructing gvariant virsystemdtest: Call at least one virSystemdCreateMachine with 'maxthreads' > 0
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
participants (2)
-
Pavel Hrdina
-
Peter Krempa