Skip to content

Commit b7bda69

Browse files
committed
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2020-07-17' into staging
* Leak fixes * One fix for running with --enable-werror on macOS * Add fuzzer test to the Gitlab-CI # gpg: Signature made Fri 17 Jul 2020 10:53:07 BST # gpg: using RSA key 27B88847EEE0250118F3EAB92ED9D774FE702DB5 # gpg: issuer "[email protected]" # gpg: Good signature from "Thomas Huth <[email protected]>" [full] # gpg: aka "Thomas Huth <[email protected]>" [full] # gpg: aka "Thomas Huth <[email protected]>" [full] # gpg: aka "Thomas Huth <[email protected]>" [unknown] # Primary key fingerprint: 27B8 8847 EEE0 2501 18F3 EAB9 2ED9 D774 FE70 2DB5 * remotes/huth-gitlab/tags/pull-request-2020-07-17: gitlab-ci.yml: Add fuzzer tests qom: Plug memory leak in "info qom-tree" configure: Fix for running with --enable-werror on macOS fuzz: Expect the cmdline in a freeable GString tests: qmp-cmd-test: fix memory leak qtest: bios-tables-test: fix a memory leak Signed-off-by: Peter Maydell <[email protected]>
2 parents 151f76c + b610eba commit b7bda69

File tree

9 files changed

+52
-19
lines changed

9 files changed

+52
-19
lines changed

.gitlab-ci.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,27 @@ build-clang:
161161
IMAGE: fedora
162162
CONFIGURE_ARGS: --cc=clang --cxx=clang++
163163
TARGETS: alpha-softmmu arm-softmmu m68k-softmmu mips64-softmmu
164-
ppc-softmmu s390x-softmmu x86_64-softmmu arm-linux-user
164+
ppc-softmmu s390x-softmmu arm-linux-user
165165
MAKE_CHECK_ARGS: check
166166

167+
build-fuzzer:
168+
<<: *native_build_job_definition
169+
variables:
170+
IMAGE: fedora
171+
script:
172+
- mkdir build
173+
- cd build
174+
- ../configure --cc=clang --cxx=clang++ --enable-fuzzing
175+
--enable-sanitizers --target-list=x86_64-softmmu
176+
- make -j"$JOBS" all check-build x86_64-softmmu/fuzz
177+
- make check
178+
- for fuzzer in i440fx-qos-fork-fuzz i440fx-qos-noreset-fuzz
179+
i440fx-qtest-reboot-fuzz virtio-scsi-flags-fuzz virtio-scsi-fuzz ; do
180+
echo Testing ${fuzzer} ... ;
181+
x86_64-softmmu/qemu-fuzz-x86_64 --fuzz-target=${fuzzer} -runs=1000
182+
|| exit 1 ;
183+
done
184+
167185
build-tci:
168186
<<: *native_build_job_definition
169187
variables:

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4198,7 +4198,7 @@ pthread_setname_np_wo_tid=no
41984198
cat > $TMPC << EOF
41994199
#include <pthread.h>
42004200
4201-
static void *f(void *p) { pthread_setname_np("QEMU"); }
4201+
static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
42024202
int main(void)
42034203
{
42044204
pthread_t thread;

qom/qom-hmp-cmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ static void print_qom_composition(Monitor *mon, Object *obj, int indent);
9696

9797
static int qom_composition_compare(const void *a, const void *b, void *ignore)
9898
{
99-
return g_strcmp0(a ? object_get_canonical_path_component(a) : NULL,
100-
b ? object_get_canonical_path_component(b) : NULL);
99+
g_autofree char *ac = object_get_canonical_path_component(a);
100+
g_autofree char *bc = object_get_canonical_path_component(b);
101+
102+
return g_strcmp0(ac, bc);
101103
}
102104

103105
static int insert_qom_composition_child(Object *obj, void *opaque)

tests/qtest/bios-tables-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,
924924
g_free(variant);
925925
g_free(tmp_path);
926926
g_free(tmp_dir_name);
927+
g_free(args);
927928
free_test_data(&data);
928929
#else
929930
g_test_skip("TPM disabled");

tests/qtest/fuzz/fuzz.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,15 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
199199
}
200200

201201
/* Run QEMU's softmmu main with the fuzz-target dependent arguments */
202-
const char *init_cmdline = fuzz_target->get_init_cmdline(fuzz_target);
203-
init_cmdline = g_strdup_printf("%s -qtest /dev/null -qtest-log %s",
204-
init_cmdline,
205-
getenv("QTEST_LOG") ? "/dev/fd/2"
206-
: "/dev/null");
207-
202+
GString *cmd_line = fuzz_target->get_init_cmdline(fuzz_target);
203+
g_string_append_printf(cmd_line,
204+
" -qtest /dev/null -qtest-log %s",
205+
getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null");
208206

209207
/* Split the runcmd into an argv and argc */
210208
wordexp_t result;
211-
wordexp(init_cmdline, &result, 0);
209+
wordexp(cmd_line->str, &result, 0);
210+
g_string_free(cmd_line, true);
212211

213212
qemu_init(result.we_wordc, result.we_wordv, NULL);
214213

tests/qtest/fuzz/fuzz.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ typedef struct FuzzTarget {
5050

5151

5252
/*
53-
* returns the arg-list that is passed to qemu/softmmu init()
54-
* Cannot be NULL
53+
* Returns the arguments that are passed to qemu/softmmu init(). Freed by
54+
* the caller.
5555
*/
56-
const char* (*get_init_cmdline)(struct FuzzTarget *);
56+
GString *(*get_init_cmdline)(struct FuzzTarget *);
5757

5858
/*
5959
* will run once, prior to running qemu/softmmu init.

tests/qtest/fuzz/i440fx_fuzz.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ static void i440fx_fuzz_qos_fork(QTestState *s,
158158

159159
static const char *i440fx_qtest_argv = TARGET_NAME " -machine accel=qtest"
160160
" -m 0 -display none";
161-
static const char *i440fx_argv(FuzzTarget *t)
161+
static GString *i440fx_argv(FuzzTarget *t)
162162
{
163-
return i440fx_qtest_argv;
163+
return g_string_new(i440fx_qtest_argv);
164164
}
165165

166166
static void fork_init(void)

tests/qtest/fuzz/qos_fuzz.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void *qos_allocate_objects(QTestState *qts, QGuestAllocator **p_alloc)
6666
return allocate_objects(qts, current_path + 1, p_alloc);
6767
}
6868

69-
static const char *qos_build_main_args(void)
69+
static GString *qos_build_main_args(void)
7070
{
7171
char **path = fuzz_path_vec;
7272
QOSGraphNode *test_node;
@@ -88,7 +88,7 @@ static const char *qos_build_main_args(void)
8888
/* Prepend the arguments that we need */
8989
g_string_prepend(cmd_line,
9090
TARGET_NAME " -display none -machine accel=qtest -m 64 ");
91-
return cmd_line->str;
91+
return cmd_line;
9292
}
9393

9494
/*
@@ -189,7 +189,7 @@ static void walk_path(QOSGraphNode *orig_path, int len)
189189
g_free(path_str);
190190
}
191191

192-
static const char *qos_get_cmdline(FuzzTarget *t)
192+
static GString *qos_get_cmdline(FuzzTarget *t)
193193
{
194194
/*
195195
* Set a global variable that we use to identify the qos_path for our

tests/qtest/qmp-cmd-test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ static void test_object_add_failure_modes(void)
230230
" 'props': {'size': 1048576 } } }");
231231
g_assert_nonnull(resp);
232232
g_assert(qdict_haskey(resp, "return"));
233+
qobject_unref(resp);
234+
233235
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
234236
" {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
235237
" 'props': {'size': 1048576 } } }");
@@ -241,6 +243,7 @@ static void test_object_add_failure_modes(void)
241243
" {'id': 'ram1' } }");
242244
g_assert_nonnull(resp);
243245
g_assert(qdict_haskey(resp, "return"));
246+
qobject_unref(resp);
244247

245248
/* attempt to create an object with a property of a wrong type */
246249
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
@@ -249,60 +252,70 @@ static void test_object_add_failure_modes(void)
249252
g_assert_nonnull(resp);
250253
/* now do it right */
251254
qmp_assert_error_class(resp, "GenericError");
255+
252256
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
253257
" {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
254258
" 'props': {'size': 1048576 } } }");
255259
g_assert_nonnull(resp);
256260
g_assert(qdict_haskey(resp, "return"));
261+
qobject_unref(resp);
257262

258263
/* delete ram1 object */
259264
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
260265
" {'id': 'ram1' } }");
261266
g_assert_nonnull(resp);
262267
g_assert(qdict_haskey(resp, "return"));
268+
qobject_unref(resp);
263269

264270
/* attempt to create an object without the id */
265271
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
266272
" {'qom-type': 'memory-backend-ram',"
267273
" 'props': {'size': 1048576 } } }");
268274
g_assert_nonnull(resp);
269275
qmp_assert_error_class(resp, "GenericError");
276+
270277
/* now do it right */
271278
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
272279
" {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
273280
" 'props': {'size': 1048576 } } }");
274281
g_assert_nonnull(resp);
275282
g_assert(qdict_haskey(resp, "return"));
283+
qobject_unref(resp);
276284

277285
/* delete ram1 object */
278286
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
279287
" {'id': 'ram1' } }");
280288
g_assert_nonnull(resp);
281289
g_assert(qdict_haskey(resp, "return"));
290+
qobject_unref(resp);
282291

283292
/* attempt to set a non existing property */
284293
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
285294
" {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
286295
" 'props': {'sized': 1048576 } } }");
287296
g_assert_nonnull(resp);
288297
qmp_assert_error_class(resp, "GenericError");
298+
289299
/* now do it right */
290300
resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':"
291301
" {'qom-type': 'memory-backend-ram', 'id': 'ram1',"
292302
" 'props': {'size': 1048576 } } }");
293303
g_assert_nonnull(resp);
294304
g_assert(qdict_haskey(resp, "return"));
305+
qobject_unref(resp);
295306

296307
/* delete ram1 object without id */
297308
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
298309
" {'ida': 'ram1' } }");
299310
g_assert_nonnull(resp);
311+
qobject_unref(resp);
300312

301313
/* delete ram1 object */
302314
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"
303315
" {'id': 'ram1' } }");
304316
g_assert_nonnull(resp);
305317
g_assert(qdict_haskey(resp, "return"));
318+
qobject_unref(resp);
306319

307320
/* delete ram1 object that does not exist anymore*/
308321
resp = qtest_qmp(qts, "{'execute': 'object-del', 'arguments':"

0 commit comments

Comments
 (0)