chardev: Fix record/replay error path NULL deref in device creation

qemu_chardev_set_replay() was being called in chardev creation to
set up replay parameters even if the chardev is NULL.

A segfault can be reproduced by specifying '-serial chardev:bad' with
an rr=record mode.

Fix this with a NULL pointer check.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Resolves: Coverity CID 1559470
Fixes: 4c193bb129 ("chardev: set record/replay on the base device of a muxed device")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20240828043337.14587-2-npiggin@gmail.com>
This commit is contained in:
Nicholas Piggin 2024-08-28 14:33:34 +10:00 committed by Marc-André Lureau
parent eb22a06445
commit 651b386205
1 changed files with 1 additions and 1 deletions

View File

@ -726,7 +726,7 @@ static Chardev *__qemu_chr_new(const char *label, const char *filename,
if (strstart(filename, "chardev:", &p)) {
chr = qemu_chr_find(p);
if (replay) {
if (replay && chr) {
qemu_chardev_set_replay(chr, &err);
if (err) {
error_report_err(err);