Skip to content

Commit ccafaeb

Browse files
committed
Add maxCommandLen setting and SetMaxCommandLen function
1 parent 69b4de2 commit ccafaeb

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

.golangci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ linters-settings:
132132
linters:
133133
enable-all: true
134134
disable:
135-
- rowserrcheck # is disabled because of generics
136-
- sqlclosecheck # is disabled because of generics
137-
- wastedassign # is disabled because of generics
138135
- exportloopref # is deprecated (since v1.60.2)
139136
- dupword
140137
- wrapcheck
@@ -144,10 +141,9 @@ linters:
144141

145142
issues:
146143
exclude:
147-
- "don't use ALL_CAPS in Go names; use CamelCase" # golint
144+
- "don't use ALL_CAPS in Go names; use CamelCase" # revive
148145
- "ST1003: should not use ALL_CAPS in Go names; use CamelCase instead" # stylecheck
149146
- "DefaultSettings`? is a global variable" # gochecknoglobals
150-
- "are|is missing in" # exhaustivestruct # v1.33
151147
exclude-dirs:
152148
- vendor/
153149
exclude-files:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
**ATTN**: This project uses [semantic versioning](http://semver.org/).
55

66
## [Unreleased]
7+
### Added
8+
- Added maxCommandLen setting and SetMaxCommandLen function.
79

810
## [v1.4.0] - 2024-11-16
911
### Fixed

option.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import "time"
44

55
// Settings contains option to Conn.
66
type Settings struct {
7-
dialTimeout time.Duration
8-
deadline time.Duration
7+
dialTimeout time.Duration
8+
deadline time.Duration
9+
maxCommandLen int
910
}
1011

1112
// DefaultSettings provides default deadline settings to Conn.
1213
var DefaultSettings = Settings{
13-
dialTimeout: DefaultDialTimeout,
14-
deadline: DefaultDeadline,
14+
dialTimeout: DefaultDialTimeout,
15+
deadline: DefaultDeadline,
16+
maxCommandLen: DefaultMaxCommandLen,
1517
}
1618

1719
// Option allows to inject settings to Settings.
@@ -30,3 +32,10 @@ func SetDeadline(timeout time.Duration) Option {
3032
s.deadline = timeout
3133
}
3234
}
35+
36+
// SetMaxCommandLen injects maxCommandLen to Settings.
37+
func SetMaxCommandLen(maxCommandLen int) Option {
38+
return func(s *Settings) {
39+
s.maxCommandLen = maxCommandLen
40+
}
41+
}

rcon.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const (
1717
// DefaultDeadline provides default deadline to tcp read/write operations.
1818
DefaultDeadline = 5 * time.Second
1919

20-
// MaxCommandLen is an artificial restriction, but it will help in case of random
20+
// DefaultMaxCommandLen is an artificial restriction, but it will help in case of random
2121
// large queries.
22-
MaxCommandLen = 1000
22+
DefaultMaxCommandLen = 1000
2323

2424
// SERVERDATA_AUTH is the first packet sent by the client,
2525
// which is used to authenticate the conn with the server.
@@ -148,7 +148,7 @@ func (c *Conn) Execute(command string) (string, error) {
148148
return "", ErrCommandEmpty
149149
}
150150

151-
if len(command) > MaxCommandLen {
151+
if c.settings.maxCommandLen > 0 && len(command) > c.settings.maxCommandLen {
152152
return "", ErrCommandTooLong
153153
}
154154

0 commit comments

Comments
 (0)