From 4a3df873e906253f5d39aef805daca2b9103a9fe Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Tue, 19 Nov 2019 10:23:58 -0500 Subject: [PATCH] Make all invalid message length errors unique --- postgres-protocol/src/message/backend.rs | 18 +++++++++--------- postgres-protocol/src/types/mod.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/postgres-protocol/src/message/backend.rs b/postgres-protocol/src/message/backend.rs index 0cf1c4f0..5de7908a 100644 --- a/postgres-protocol/src/message/backend.rs +++ b/postgres-protocol/src/message/backend.rs @@ -53,7 +53,7 @@ impl Header { if len < 4 { return Err(io::Error::new( io::ErrorKind::InvalidData, - "invalid message length", + "invalid message length: header length < 4", )); } @@ -123,7 +123,7 @@ impl Message { if len < 4 { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: parsing u32", )); } @@ -271,7 +271,7 @@ impl Message { if !buf.is_empty() { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: expected buffer to be empty", )); } @@ -376,7 +376,7 @@ impl<'a> FallibleIterator for SaslMechanisms<'a> { if self.0.len() != 1 { return Err(io::Error::new( io::ErrorKind::InvalidData, - "invalid message length", + "invalid message length: expected to be at end of iterator for sasl", )); } Ok(None) @@ -488,7 +488,7 @@ impl<'a> FallibleIterator for ColumnFormats<'a> { } else { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: wrong column formats", )); } } @@ -564,7 +564,7 @@ impl<'a> FallibleIterator for DataRowRanges<'a> { } else { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: datarowrange is not empty", )); } } @@ -622,7 +622,7 @@ impl<'a> FallibleIterator for ErrorFields<'a> { } else { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: error fields is not drained", )); } } @@ -718,7 +718,7 @@ impl<'a> FallibleIterator for Parameters<'a> { } else { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: parameters is not drained", )); } } @@ -794,7 +794,7 @@ impl<'a> FallibleIterator for Fields<'a> { } else { return Err(io::Error::new( io::ErrorKind::InvalidInput, - "invalid message length", + "invalid message length: field is not drained", )); } } diff --git a/postgres-protocol/src/types/mod.rs b/postgres-protocol/src/types/mod.rs index 8af7486e..8412f31d 100644 --- a/postgres-protocol/src/types/mod.rs +++ b/postgres-protocol/src/types/mod.rs @@ -308,11 +308,11 @@ pub fn varbit_from_sql<'a>( ) -> Result, StdBox> { let len = buf.read_i32::()?; if len < 0 { - return Err("invalid varbit length".into()); + return Err("invalid varbit length: varbit < 0".into()); } let bytes = (len as usize + 7) / 8; if buf.len() != bytes { - return Err("invalid message length".into()); + return Err("invalid message length: varbit mismatch".into()); } Ok(Varbit { @@ -362,7 +362,7 @@ pub fn timestamp_to_sql(v: i64, buf: &mut BytesMut) { pub fn timestamp_from_sql(mut buf: &[u8]) -> Result> { let v = buf.read_i64::()?; if !buf.is_empty() { - return Err("invalid message length".into()); + return Err("invalid message length: timestamp not drained".into()); } Ok(v) } @@ -382,7 +382,7 @@ pub fn date_to_sql(v: i32, buf: &mut BytesMut) { pub fn date_from_sql(mut buf: &[u8]) -> Result> { let v = buf.read_i32::()?; if !buf.is_empty() { - return Err("invalid message length".into()); + return Err("invalid message length: date not drained".into()); } Ok(v) } @@ -402,7 +402,7 @@ pub fn time_to_sql(v: i64, buf: &mut BytesMut) { pub fn time_from_sql(mut buf: &[u8]) -> Result> { let v = buf.read_i64::()?; if !buf.is_empty() { - return Err("invalid message length".into()); + return Err("invalid message length: time not drained".into()); } Ok(v) } @@ -417,7 +417,7 @@ pub fn macaddr_to_sql(v: [u8; 6], buf: &mut BytesMut) { #[inline] pub fn macaddr_from_sql(buf: &[u8]) -> Result<[u8; 6], StdBox> { if buf.len() != 6 { - return Err("invalid message length".into()); + return Err("invalid message length: macaddr length mismatch".into()); } let mut out = [0; 6]; out.copy_from_slice(buf); @@ -434,7 +434,7 @@ pub fn uuid_to_sql(v: [u8; 16], buf: &mut BytesMut) { #[inline] pub fn uuid_from_sql(buf: &[u8]) -> Result<[u8; 16], StdBox> { if buf.len() != 16 { - return Err("invalid message length".into()); + return Err("invalid message length: uuid size mismatch".into()); } let mut out = [0; 16]; out.copy_from_slice(buf); @@ -615,7 +615,7 @@ impl<'a> FallibleIterator for ArrayValues<'a> { fn next(&mut self) -> Result>, StdBox> { if self.remaining == 0 { if !self.buf.is_empty() { - return Err("invalid message length".into()); + return Err("invalid message length: arrayvalue not drained".into()); } return Ok(None); } @@ -944,7 +944,7 @@ impl<'a> FallibleIterator for PathPoints<'a> { fn next(&mut self) -> Result, StdBox> { if self.remaining == 0 { if !self.buf.is_empty() { - return Err("invalid message length".into()); + return Err("invalid message length: path points not drained".into()); } return Ok(None); }