Browse Source

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.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-id: 2018110615.5139-1-peter.maydell@linaro.org
tags/v3.1.0-rc1
Peter Maydell 7 months ago
parent
commit
0b57007755
1 changed files with 13 additions and 3 deletions
  1. 13
    3
      replay/replay-internal.c

+ 13
- 3
replay/replay-internal.c View File

@@ -35,6 +35,12 @@ static void replay_write_error(void)
35 35
     }
36 36
 }
37 37
 
38
+static void replay_read_error(void)
39
+{
40
+    error_report("error reading the replay data");
41
+    exit(1);
42
+}
43
+
38 44
 void replay_put_byte(uint8_t byte)
39 45
 {
40 46
     if (replay_file) {
@@ -83,7 +89,11 @@ uint8_t replay_get_byte(void)
83 89
 {
84 90
     uint8_t byte = 0;
85 91
     if (replay_file) {
86
-        byte = getc(replay_file);
92
+        int r = getc(replay_file);
93
+        if (r == EOF) {
94
+            replay_read_error();
95
+        }
96
+        byte = r;
87 97
     }
88 98
     return byte;
89 99
 }
@@ -126,7 +136,7 @@ void replay_get_array(uint8_t *buf, size_t *size)
126 136
     if (replay_file) {
127 137
         *size = replay_get_dword();
128 138
         if (fread(buf, 1, *size, replay_file) != *size) {
129
-            error_report("replay read error");
139
+            replay_read_error();
130 140
         }
131 141
     }
132 142
 }
@@ -137,7 +147,7 @@ void replay_get_array_alloc(uint8_t **buf, size_t *size)
137 147
         *size = replay_get_dword();
138 148
         *buf = g_malloc(*size);
139 149
         if (fread(*buf, 1, *size, replay_file) != *size) {
140
-            error_report("replay read error");
150
+            replay_read_error();
141 151
         }
142 152
     }
143 153
 }

Loading…
Cancel
Save