Skip to content

Commit

Permalink
tests/qtest/migration-test: Fix bootfile cleanup handling
Browse files Browse the repository at this point in the history
If you invoke the migration-test binary in such a way that it doesn't run
any tests, then we never call bootfile_create(), and at the end of
main() bootfile_delete() will try to unlink(NULL), which is not valid.
This can happen if for instance you tell the test binary to run a
subset of tests that turns out to be empty, like this:

 (cd build/asan && QTEST_QEMU_BINARY=./qemu-system-x86_64 ./tests/qtest/migration-test --tap -k -p bang)
 # random seed: R02S6501b289ff8ced4231ba452c3a87bc6f
 # Skipping test: userfaultfd not available
 1..0
 ../../tests/qtest/migration-test.c:182:12: runtime error: null pointer passed as argument 1, which is declared to never be null
 /usr/include/unistd.h:858:48: note: nonnull attribute specified here

Handle this by making bootfile_delete() not needing to do anything
because bootfile_create() was never called.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
[fixed conflict with aee07f2]
Signed-off-by: Fabiano Rosas <farosas@suse.de>
  • Loading branch information
pm215 authored and Fabiano Rosas committed Sep 3, 2024
1 parent ceb1ab1 commit d278455
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/qtest/migration-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ static char *bootpath;

static void bootfile_delete(void)
{
if (!bootpath) {
return;
}
unlink(bootpath);
g_free(bootpath);
bootpath = NULL;
Expand All @@ -156,10 +159,7 @@ static void bootfile_create(char *dir, bool suspend_me)
unsigned char *content;
size_t len;

if (bootpath) {
bootfile_delete();
}

bootfile_delete();
bootpath = g_strdup_printf("%s/bootsect", dir);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
/* the assembled x86 boot sector should be exactly one sector large */
Expand Down

0 comments on commit d278455

Please sign in to comment.