replay: Exit on errors reading from replay log
PATCH 1/1 replay: Exit on errors reading from replay log
Currently replay_get_byte() does not check for an error from getc(). Coverity points out (CID 1390622) that this could result in unexpected behaviour (such as looping forever, if we use the replay_get_dword() return value for a loop count). We don't expect reads from the replay log to fail, and if they do there is no way we can continue. So make them fatal errors.
---
Disclaimer: checked only with "make check".
replay/replay-internal.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
replay/replay-internal.c +13 -3
@@ -35,6 +35,12 @@ static void replay_write_error(void) } } +static void replay_read_error (void ) +{ +error_report ("error reading the replay data" ); +exit (1 ); +} +void replay_put_byte (uint8_t byte) {if (replay_file) {
@@ -83,7 +89,11 @@ uint8_t replay_get_byte(void) {uint8_t byte =0 ;if (replay_file) { - byte =getc (replay_file); +int r =getc (replay_file); +if (r ==EOF ) { +replay_read_error (); + } + byte = r; }return byte; }
@@ -126,7 +136,7 @@ void replay_get_array(uint8_t *buf, size_t *size)if (replay_file) { *size =replay_get_dword ();if (fread (buf,1 , *size, replay_file) != *size) { -error_report ("replay read error" ); +replay_read_error (); } } }
@@ -137,7 +147,7 @@ void replay_get_array_alloc(uint8_t **buf, size_t *size) *size =replay_get_dword (); *buf =g_malloc (*size);if (fread (*buf,1 , *size, replay_file) != *size) { -error_report ("replay read error" ); +replay_read_error (); } } }
Signature · 1 line
2.19.1
Quoted 56 lines · Peter Maydell
Currently
replay_get_byte()does not check for an error fromgetc(). Coverity points out (CID 1390622) that this could result in unexpected behaviour (such as looping forever, if we use thereplay_get_dword()return value for a loop count). We don't expect reads from the replay log to fail, and if they do there is no way we can continue. So make them fatal errors.Signed-off-by Peter Maydell <[email protected]>---
Disclaimer: checked only with "make check".replay/replay-internal.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)replay/replay-internal.c +12
-2@@ -35,6 +35,12 @@ static void replay_write_error(void) } } +static void replay_read_error (void ) +{ +error_report ("error reading the replay data" ); +exit (1 ); +} +void replay_put_byte (uint8_t byte) {if (replay_file) {@@ -83,7 +89,11 @@ uint8_t replay_get_byte(void) {uint8_t byte =0 ;if (replay_file) { - byte =getc (replay_file); +int r =getc (replay_file); +if (r ==EOF ) { +replay_read_error (); + } + byte = r; }return byte; }@@ -126,7 +136,7 @@ void replay_get_array(uint8_t *buf, size_t *size)if (replay_file) { *size =replay_get_dword ();if (fread (buf,1 , *size, replay_file) != *size) { -error_report ("replay read error" ); +replay_read_error (); } } }
replay/replay-internal.c void replay_get_array_alloc(uint8_t **buf, size_t *size) · line 153
Quoted 8 lines
replay/replay-internal.c +1
-1@@ -137,7 +147,7 @@ void replay_get_array_alloc(uint8_t **buf, size_t *size) *size =replay_get_dword (); *buf =g_malloc (*size);if (fread (*buf,1 , *size, replay_file) != *size) { -error_report ("replay read error" ); +replay_read_error (); } } }
Makes sense, can you apply it directly to qemu.git as soon as Pavel reviews it (or in some time if he doesn't)?
Thanks,
Paolo
Peter Maydell
AppliedQuoted 9 lines · Paolo Bonzini
Quoted 8 lines · Peter Maydell
Currently
replay_get_byte()does not check for an error fromgetc(). Coverity points out (CID 1390622) that this could result in unexpected behaviour (such as looping forever, if we use thereplay_get_dword()return value for a loop count). We don't expect reads from the replay log to fail, and if they do there is no way we can continue. So make them fatal errors.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Peter Maydell <[email protected]>---
Makes sense, can you apply it directly to qemu.git as soon as Pavel reviews it (or in some time if he doesn't)?
Applied to master, thanks.
-- PMM
Quoted 10 lines
From: Peter Maydell [mailto:[email protected]] Currently
replay_get_byte()does not check for an error fromgetc(). Coverity points out (CID 1390622) that this could result in unexpected behaviour (such as looping forever, if we use thereplay_get_dword()return value for a loop count). We don't expect reads from the replay log to fail, and if they do there is no way we can continue. So make them fatal errors.Signed-off-by Peter Maydell <[email protected]>
Quoted 55 lines
---
Disclaimer: checked only with "make check".replay/replay-internal.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)replay/replay-internal.c +13
-4@@ -35,6 +35,12 @@ static void replay_write_error(void) } } +static void replay_read_error (void ) +{ +error_report ("error reading the replay data" ); +exit (1 ); +} +void replay_put_byte (uint8_t byte) {if (replay_file) {@@ -83,7 +89,11 @@ uint8_t replay_get_byte(void) {uint8_t byte =0 ;if (replay_file) { - byte =getc (replay_file); +int r =getc (replay_file); +if (r ==EOF ) { +replay_read_error (); + } + byte = r; }return byte; }@@ -126,7 +136,7 @@ void replay_get_array(uint8_t *buf, size_t *size)if (replay_file) { *size =replay_get_dword ();if (fread (buf,1 , *size, replay_file) != *size) { -error_report ("replay read error" ); +replay_read_error (); } } }@@ -137,7 +147,7 @@ void replay_get_array_alloc(uint8_t **buf, size_t *size) *size =replay_get_dword (); *buf =g_malloc (*size);if (fread (*buf,1 , *size, replay_file) != *size) { -error_report ("replay read error" ); +replay_read_error (); } } } --
Quoted 1 line
2.19.1
Pavel Dovgalyuk