Skip to content

Commit 4a6f6b5

Browse files
authored
smb: fix panic in ntlmssp when unmarshaling (zmap#333)
* smb: panic in ntlmssp when unmarshaling There are two errors here: 1. The offsets to the ParentBuf are not checked to be in-bounds 2. Types are uint64, but subtracted and compared to > 0. This allows underflow during subtraction of the size. * smb: check offset/length/size are positive after cast
1 parent a1fba22 commit 4a6f6b5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/smb/ntlmssp/ntlmssp.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,27 @@ func (s *AvPairSlice) UnmarshalBinary(buf []byte, meta *encoder.Metadata) error
172172
if !ok {
173173
return errors.New(fmt.Sprintf("Cannot unmarshal field '%s'. Missing offset\n", meta.CurrField))
174174
}
175-
for i := l; i > 0; {
175+
offset := int64(o)
176+
length := int64(l)
177+
if offset < 0 || length < 0 {
178+
return fmt.Errorf("AvPairSlice.UnmarshalBinary: offset (%d) and length (%d) should be positive",
179+
offset, length)
180+
}
181+
if offset+length > int64(len(meta.ParentBuf)) {
182+
return fmt.Errorf("AvPairSlice.UnmarshalBinary: ParentBuf overrun")
183+
}
184+
for i := length; i > 0; {
176185
var avPair AvPair
177-
err := encoder.Unmarshal(meta.ParentBuf[o:o+i], &avPair)
186+
err := encoder.Unmarshal(meta.ParentBuf[offset:offset+i], &avPair)
178187
if err != nil {
179188
return err
180189
}
181190
slice = append(slice, avPair)
182-
size := avPair.Size()
183-
o += size
191+
size := int64(avPair.Size())
192+
if size < 0 {
193+
return fmt.Errorf("AvPairSlice.UnmarshalBinary: Invalid avPair.Size() %d", size)
194+
}
195+
offset += size
184196
i -= size
185197
}
186198
*s = slice

0 commit comments

Comments
 (0)