[PATCH] chardev/char-file: fix failure path

Vladimir Sementsov-Ogievskiy posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251014145029.949285-1-vsementsov@yandex-team.ru
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
chardev/char-file.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] chardev/char-file: fix failure path
Posted by Vladimir Sementsov-Ogievskiy 1 month ago
'in' will be -1 when file->in is unset. Let's not try to close
invalid fd.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Coverity: CID 1630444
Fixes: 69620c091d62f "chardev: qemu_chr_open_fd(): add errp"
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---

I was going to send it inside v3 of "chardev: postpone connect", but it
seems the discussion may continue there, so, decided to send this small
fix in separate.

 chardev/char-file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/chardev/char-file.c b/chardev/char-file.c
index 89e9cb849c..1f7adf592f 100644
--- a/chardev/char-file.c
+++ b/chardev/char-file.c
@@ -94,7 +94,9 @@ static void qmp_chardev_open_file(Chardev *chr,
 
     if (!qemu_chr_open_fd(chr, in, out, errp)) {
         qemu_close(out);
-        qemu_close(in);
+        if (in >= 0) {
+            qemu_close(in);
+        }
         return;
     }
 #endif
-- 
2.48.1
Re: [PATCH] chardev/char-file: fix failure path
Posted by Marc-André Lureau 1 month ago
On Tue, Oct 14, 2025 at 6:51 PM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> 'in' will be -1 when file->in is unset. Let's not try to close
> invalid fd.
>
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Coverity: CID 1630444
> Fixes: 69620c091d62f "chardev: qemu_chr_open_fd(): add errp"
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>
> I was going to send it inside v3 of "chardev: postpone connect", but it
> seems the discussion may continue there, so, decided to send this small
> fix in separate.
>
>  chardev/char-file.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/chardev/char-file.c b/chardev/char-file.c
> index 89e9cb849c..1f7adf592f 100644
> --- a/chardev/char-file.c
> +++ b/chardev/char-file.c
> @@ -94,7 +94,9 @@ static void qmp_chardev_open_file(Chardev *chr,
>
>      if (!qemu_chr_open_fd(chr, in, out, errp)) {
>          qemu_close(out);
> -        qemu_close(in);
> +        if (in >= 0) {
> +            qemu_close(in);
> +        }
>          return;
>      }
>  #endif
> --
> 2.48.1
>
>


-- 
Marc-André Lureau
Re: [PATCH] chardev/char-file: fix failure path
Posted by Vladimir Sementsov-Ogievskiy 2 weeks ago
On 14.10.25 17:53, Marc-André Lureau wrote:
> On Tue, Oct 14, 2025 at 6:51 PM Vladimir Sementsov-Ogievskiy
> <vsementsov@yandex-team.ru> wrote:
>> 'in' will be -1 when file->in is unset. Let's not try to close
>> invalid fd.
>>
>> Reported-by: Peter Maydell<peter.maydell@linaro.org>
>> Coverity: CID 1630444
>> Fixes: 69620c091d62f "chardev: qemu_chr_open_fd(): add errp"
>> Signed-off-by: Vladimir Sementsov-Ogievskiy<vsementsov@yandex-team.ru>
> Reviewed-by: Marc-André Lureau<marcandre.lureau@redhat.com>

Hi, isn't it lost? It's still not in master.. Or did you queued already?


-- 
Best regards,
Vladimir