]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fix bug in `BufReader::fill_buf` when reaching EOF
authorMatt Corallo <git@bluematt.me>
Fri, 16 Aug 2024 18:46:24 +0000 (18:46 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 19 Aug 2024 14:55:28 +0000 (14:55 +0000)
When we reach EOF we may return a full buffer when we should return
an empty one.

lightning/src/util/ser.rs

index 19281110d6a95914302ea5e5ccf62d5cfdbd161d..fbe1933a0cb18c00d4328dc7071d88d5d93a900d 100644 (file)
@@ -111,7 +111,11 @@ impl<'a, R: Read> BufRead for BufReader<'a, R> {
                        self.is_consumed = count == 0;
                }
 
-               Ok(&self.buf[..])
+               if self.is_consumed {
+                       Ok(&[])
+               } else {
+                       Ok(&self.buf[..])
+               }
        }
 
        #[inline]