Skip to content

Commit

Permalink
add a length check to fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Vivet committed May 23, 2017
1 parent 5f197b9 commit 7649370
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ pub fn parse_ssh_packet(i: &[u8]) -> IResult<&[u8], (SshPacket, &[u8])> {
do_parse!(i,
packet_length: be_u32 >>
padding_length: be_u8 >>
error_if!(padding_length as u32 + 1 > packet_length, Err::Code(ErrorKind::Custom(128))) >>
payload: flat_map!(
take!(packet_length - padding_length as u32 - 1),
switch!(be_u8,
Expand Down
10 changes: 9 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Public API tests
use nom::IResult;
use nom::{IResult,ErrorKind,Err};

use super::ssh::*;

Expand Down Expand Up @@ -133,3 +133,11 @@ fn test_new_keys() {
let res = parse_ssh_packet(&SERVER_NEW_KEYS);
assert_eq!(res, expected);
}

#[test]
fn test_invalid_packet0() {
let data = b"\x00\x00\x00\x00\x00\x00\x00\x00";
let expected = IResult::Error(Err::Code(ErrorKind::Custom(128)));
let res = parse_ssh_packet(data);
assert_eq!(res, expected);
}

0 comments on commit 7649370

Please sign in to comment.