Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smb: fix panic in ntlmssp when unmarshaling #333

Merged
merged 2 commits into from
Nov 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/smb/ntlmssp/ntlmssp.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,27 @@ func (s *AvPairSlice) UnmarshalBinary(buf []byte, meta *encoder.Metadata) error
if !ok {
return errors.New(fmt.Sprintf("Cannot unmarshal field '%s'. Missing offset\n", meta.CurrField))
}
for i := l; i > 0; {
offset := int64(o)
length := int64(l)
if offset < 0 || length < 0 {
return fmt.Errorf("AvPairSlice.UnmarshalBinary: offset (%d) and length (%d) should be positive",
offset, length)
}
if offset+length > int64(len(meta.ParentBuf)) {
justinbastress marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("AvPairSlice.UnmarshalBinary: ParentBuf overrun")
}
for i := length; i > 0; {
var avPair AvPair
err := encoder.Unmarshal(meta.ParentBuf[o:o+i], &avPair)
err := encoder.Unmarshal(meta.ParentBuf[offset:offset+i], &avPair)
if err != nil {
return err
}
slice = append(slice, avPair)
size := avPair.Size()
o += size
size := int64(avPair.Size())
if size < 0 {
return fmt.Errorf("AvPairSlice.UnmarshalBinary: Invalid avPair.Size() %d", size)
}
offset += size
i -= size
}
*s = slice
Expand Down