Skip to content

Commit 4f934e8

Browse files
fixed bounds check for tls, updated buffer 8192
1 parent 6c5da7c commit 4f934e8

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Options:
5151
-h Show this help message and exit.
5252
-D Display list of interfaces and exit.
5353
-b int
54-
The maximum size of packet queue. (default 4096)
54+
The maximum size of packet queue. (default 8192)
5555
-c int
5656
The maximum number of packets to capture.
5757
-e string
@@ -84,7 +84,7 @@ Output:
8484
- Promiscuous Mode: true
8585
- Timeout: 0s
8686
- Number of Packets: 0
87-
- Packet Buffer Size: 4096
87+
- Packet Buffer Size: 8192
8888
- BPF Filter: "port 53"
8989
- Verbose: false
9090
```

cmd/mshark/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func root(args []string) error {
102102
)
103103
flags.DurationVar(&conf.Timeout, "t", 0, "The maximum duration of the packet capture process. Example: 5s")
104104
flags.IntVar(&conf.PacketCount, "c", 0, "The maximum number of packets to capture.")
105-
packetBuffer := flags.Int("b", 4096, "The maximum size of packet queue.")
105+
packetBuffer := flags.Int("b", 8192, "The maximum size of packet queue.")
106106
flags.StringVar(&conf.Expr, "e", "", `BPF filter expression. Example: "ip proto tcp".`)
107107
flags.BoolFunc("D", "Display list of interfaces and exit.", func(flagValue string) error {
108108
if err := displayInterfaces(); err != nil {
@@ -143,7 +143,7 @@ func root(args []string) error {
143143
conf.Snaplen = *snaplen
144144

145145
if *packetBuffer <= 0 {
146-
*packetBuffer = 4096
146+
*packetBuffer = 8192
147147
}
148148
conf.PacketBuffer = *packetBuffer
149149

layers/tls.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,21 @@ func (t *TLSMessage) Parse(data []byte) error {
549549
if ctdesc == "Unknown" {
550550
break
551551
}
552+
if len(data) < 3 {
553+
break
554+
}
552555
ver := binary.BigEndian.Uint16(data[1:3])
553556
verdesc := verdesc(ver)
554557
if verdesc == "Unknown" {
555558
break
556559
}
560+
if len(data) < headerSizeTLS {
561+
break
562+
}
557563
rlen := binary.BigEndian.Uint16(data[3:headerSizeTLS])
558-
rb := uint16(headerSizeTLS + rlen)
559-
if rb > uint16(len(data)) {
560-
rb = uint16(len(data))
564+
rb := min(uint16(headerSizeTLS+rlen), uint16(len(data)))
565+
if rb < headerSizeTLS {
566+
break
561567
}
562568
r := &Record{
563569
ContentType: ctype,

mshark.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Config struct {
3838
Promisc bool // Promiscuous mode. This setting is ignored for "any" interface.
3939
Timeout time.Duration // The maximum duration of the packet capture process.
4040
PacketCount int // The maximum number of packets to capture.
41-
PacketBuffer int // The maximum size for packet buffer (Default: 4096)
41+
PacketBuffer int // The maximum size for packet buffer (Default: 8192)
4242
Expr string // BPF filter expression.
4343
}
4444

@@ -114,7 +114,7 @@ func (mw *Writer) WritePacket(timestamp time.Time, data []byte) error {
114114
// - Promiscuous Mode: true
115115
// - Timeout: 5s
116116
// - Number of Packets: 0
117-
// - Packet Buffer Size: 4096
117+
// - Packet Buffer Size: 8192
118118
// - BPF Filter: "ip proto tcp"
119119
// - Verbose: true
120120
func (mw *Writer) WriteHeader(c *Config) error {
@@ -244,7 +244,7 @@ func OpenLive(conf *Config, pw ...PacketWriter) error {
244244

245245
b := make([]byte, conf.Snaplen)
246246
if conf.PacketBuffer <= 0 {
247-
conf.PacketBuffer = 4096
247+
conf.PacketBuffer = 8192
248248
}
249249
packetQueue := make(chan []byte, conf.PacketBuffer)
250250

0 commit comments

Comments
 (0)