* [PATCH] replay: Improve assert in replay_char_read_all_load()
@ 2025-11-24 17:34 Peter Maydell
2025-11-25 6:26 ` Philippe Mathieu-Daudé
2025-11-25 21:49 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2025-11-24 17:34 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Alex Bennée
In replay_char_read_all_load() we get a buffer and size from the
replay log. We know the size has to fit an int because of how we
write the log. However the way we assert this is wrong: we cast the
size_t from replay_get_array() to an int and then check that it is
non-negative. This misses cases where an over-large size is
truncated into a positive value by the cast.
Replace the assertion with checking that the size is in-range
before doing the cast.
Coverity complained about the possible overflow: CID 1643440.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
replay/replay-char.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/replay/replay-char.c b/replay/replay-char.c
index 81dc416e988..4e58dd154af 100644
--- a/replay/replay-char.c
+++ b/replay/replay-char.c
@@ -126,8 +126,8 @@ int replay_char_read_all_load(uint8_t *buf)
int res;
replay_get_array(buf, &size);
replay_finish_event();
+ assert(size <= INT_MAX);
res = (int)size;
- assert(res >= 0);
return res;
} else if (replay_next_event_is(EVENT_CHAR_READ_ALL_ERROR)) {
int res = replay_get_dword();
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] replay: Improve assert in replay_char_read_all_load()
2025-11-24 17:34 [PATCH] replay: Improve assert in replay_char_read_all_load() Peter Maydell
@ 2025-11-25 6:26 ` Philippe Mathieu-Daudé
2025-11-25 21:49 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-25 6:26 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Paolo Bonzini, Alex Bennée
On 24/11/25 18:34, Peter Maydell wrote:
> In replay_char_read_all_load() we get a buffer and size from the
> replay log. We know the size has to fit an int because of how we
> write the log. However the way we assert this is wrong: we cast the
> size_t from replay_get_array() to an int and then check that it is
> non-negative. This misses cases where an over-large size is
> truncated into a positive value by the cast.
>
> Replace the assertion with checking that the size is in-range
> before doing the cast.
>
> Coverity complained about the possible overflow: CID 1643440.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> replay/replay-char.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] replay: Improve assert in replay_char_read_all_load()
2025-11-24 17:34 [PATCH] replay: Improve assert in replay_char_read_all_load() Peter Maydell
2025-11-25 6:26 ` Philippe Mathieu-Daudé
@ 2025-11-25 21:49 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-25 21:49 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Paolo Bonzini, Alex Bennée
On 24/11/25 18:34, Peter Maydell wrote:
> In replay_char_read_all_load() we get a buffer and size from the
> replay log. We know the size has to fit an int because of how we
> write the log. However the way we assert this is wrong: we cast the
> size_t from replay_get_array() to an int and then check that it is
> non-negative. This misses cases where an over-large size is
> truncated into a positive value by the cast.
>
> Replace the assertion with checking that the size is in-range
> before doing the cast.
>
> Coverity complained about the possible overflow: CID 1643440.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> replay/replay-char.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Queued, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-25 21:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24 17:34 [PATCH] replay: Improve assert in replay_char_read_all_load() Peter Maydell
2025-11-25 6:26 ` Philippe Mathieu-Daudé
2025-11-25 21:49 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).