Skip to content

Commit

Permalink
Test error cases: readUTF8STRING
Browse files Browse the repository at this point in the history
  • Loading branch information
lor00x committed Dec 4, 2014
1 parent effe521 commit 695edfc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion message/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func (b Bytes) ReadPrimitiveSubBytes(class int, tag int, typeTag int) (value int
end := *b.offset + tagAndLength.Length

// Check we got enough bytes to process
if end > len(b.bytes)+1 {
if end > len(b.bytes) {
// err = LdapError{fmt.Sprintf("ReadPrimitiveSubBytes: data truncated: expecting %d bytes at offset %d but only %d bytes are remaining (start: %d, length: %d, end: %d, len(b): %d, bytes: %#+v)", tagAndLength.Length, *b.offset, len(b.bytes)-start, start, tagAndLength.Length, end, len(b.bytes), b.bytes)}
err = LdapError{fmt.Sprintf("ReadPrimitiveSubBytes: data truncated: expecting %d bytes at offset %d but only %d bytes are remaining", tagAndLength.Length, *b.offset, len(b.bytes)-start)}
return
}
Expand Down
24 changes: 23 additions & 1 deletion message/read_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ readTaggedPositiveINTEGER: Invalid INTEGER value -97 ! Expected value between 0
bytes: Bytes{
offset: NewInt(0),
bytes: []byte{
0x30, 0x0c,
0x30, 0x0d,
0x02, 0x01, 0x0a, // messageID
0x50, 0x08, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Abandon request [APPLICATION 16] MessageID = 0x0f ff ff ff ff ff ff ff
},
Expand Down Expand Up @@ -297,6 +297,28 @@ ReadSubBytes:
readComponents:
readENUMERATED: Invalid ENUMERATED VALUE 4095`,
},

{
label: "client delRequest, invalid length for the protocolOp",
bytes: Bytes{
offset: NewInt(0),
bytes: []byte{
// 30400201274a3b636e3d4120636f6d706c657820706572736f6e5c2c207665727920636f6d706c657820212c6f753d636f6e73756d6572732c6f753d73797374656d
0x30, 0x40, 0x02, 0x01, 0x27,
0x4a, 0x3c, 0x63, 0x6e, 0x3d, 0x41, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x78, 0x20, 0x70, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x5c, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x79, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x78, 0x20, 0x21, 0x2c, 0x6f, 0x75, 0x3d, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x73, 0x2c, 0x6f, 0x75, 0x3d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d,
},
},
err: `ReadLDAPMessage:
ReadSubBytes:
readComponents:
readProtocolOp:
readDelRequest:
readTaggedLDAPDN:
readTaggedLDAPString:
readTaggedUTF8STRING:
ReadPrimitiveSubBytes: data truncated: expecting 60 bytes at offset 5 but only 59 bytes are remaining`,
},

// // Request 2: server => bind response
// {
// bytes: Bytes{
Expand Down

0 comments on commit 695edfc

Please sign in to comment.