Skip to content

Commit a2fcd5b

Browse files
authored
Merge pull request #252 from rabbitmq/lukebakken/codeql-alert
Address CodeQL warning
2 parents 7305875 + d968382 commit a2fcd5b

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ jobs:
3838
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
3939

4040
steps:
41-
- uses: actions/checkout@v3
41+
- uses: actions/checkout@v4
4242
- name: Initialize CodeQL
43-
uses: github/codeql-action/init@v2
43+
uses: github/codeql-action/init@v3
4444
with:
4545
languages: ${{ matrix.language }}
4646
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -51,7 +51,7 @@ jobs:
5151
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5252
# If this step fails, then you should remove it and run the build manually (see below)
5353
- name: Autobuild
54-
uses: github/codeql-action/autobuild@v2
54+
uses: github/codeql-action/autobuild@v3
5555

5656
# ℹ️ Command-line programs to run using the OS shell.
5757
# 📚 https://git.io/JvXDl
@@ -65,4 +65,4 @@ jobs:
6565
# make release
6666

6767
- name: Perform CodeQL Analysis
68-
uses: github/codeql-action/analyze@v2
68+
uses: github/codeql-action/analyze@v3

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
name: lint
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/setup-go@v3
17+
- uses: actions/setup-go@v5
1818
with:
1919
go-version: 'stable'
2020
check-latest: true
21-
- uses: actions/checkout@v3
22-
- uses: golangci/golangci-lint-action@v3
21+
- uses: actions/checkout@v4
22+
- uses: golangci/golangci-lint-action@v4
2323
with:
2424
version: latest
2525
only-new-issues: false

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
matrix:
1616
go-version: ['oldstable', 'stable']
1717
steps:
18-
- uses: actions/checkout@v3
19-
- uses: actions/setup-go@v3
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
2020
with:
2121
go-version: ${{ matrix.go-version }}
2222
check-latest: true
@@ -43,8 +43,8 @@ jobs:
4343
ports:
4444
- 5672:5672
4545
steps:
46-
- uses: actions/checkout@v3
47-
- uses: actions/setup-go@v3
46+
- uses: actions/checkout@v4
47+
- uses: actions/setup-go@v5
4848
with:
4949
go-version: ${{ matrix.go-version }}
5050
check-latest: true

connection.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
platform = "golang"
3333
// Safer default that makes channel leaks a lot easier to spot
3434
// before they create operational headaches. See https://github.com/rabbitmq/rabbitmq-server/issues/1593.
35-
defaultChannelMax = (2 << 10) - 1
35+
defaultChannelMax = uint16((2 << 10) - 1)
3636
defaultLocale = "en_US"
3737
)
3838

@@ -49,7 +49,7 @@ type Config struct {
4949
// bindings on the server. Dial sets this to the path parsed from the URL.
5050
Vhost string
5151

52-
ChannelMax int // 0 max channels means 2^16 - 1
52+
ChannelMax uint16 // 0 max channels means 2^16 - 1
5353
FrameSize int // 0 max bytes means unlimited
5454
Heartbeat time.Duration // less than 1s uses the server's interval
5555

@@ -991,13 +991,13 @@ func (c *Connection) openTune(config Config, auth Authentication) error {
991991

992992
// When the server and client both use default 0, then the max channel is
993993
// only limited by uint16.
994-
c.Config.ChannelMax = pick(config.ChannelMax, int(tune.ChannelMax))
994+
c.Config.ChannelMax = pickUInt16(config.ChannelMax, tune.ChannelMax)
995995
if c.Config.ChannelMax == 0 {
996996
c.Config.ChannelMax = defaultChannelMax
997997
}
998-
c.Config.ChannelMax = min(c.Config.ChannelMax, maxChannelMax)
998+
c.Config.ChannelMax = minUInt16(c.Config.ChannelMax, maxChannelMax)
999999

1000-
c.allocator = newAllocator(1, c.Config.ChannelMax)
1000+
c.allocator = newAllocator(1, int(c.Config.ChannelMax))
10011001

10021002
c.m.Unlock()
10031003

@@ -1104,13 +1104,35 @@ func max(a, b int) int {
11041104
return b
11051105
}
11061106

1107+
func maxUInt16(a, b uint16) uint16 {
1108+
if a > b {
1109+
return a
1110+
}
1111+
return b
1112+
}
1113+
11071114
func min(a, b int) int {
11081115
if a < b {
11091116
return a
11101117
}
11111118
return b
11121119
}
11131120

1121+
func minUInt16(a, b uint16) uint16 {
1122+
if a < b {
1123+
return a
1124+
}
1125+
return b
1126+
}
1127+
1128+
func pickUInt16(client, server uint16) uint16 {
1129+
if client == 0 || server == 0 {
1130+
return maxUInt16(client, server)
1131+
} else {
1132+
return minUInt16(client, server)
1133+
}
1134+
}
1135+
11141136
func pick(client, server int) int {
11151137
if client == 0 || server == 0 {
11161138
return max(client, server)

integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func TestIntegrationChannelIDsExhausted(t *testing.T) {
478478
}
479479
defer c.Close()
480480

481-
for i := 1; i <= c.Config.ChannelMax; i++ {
481+
for i := uint16(1); i <= c.Config.ChannelMax; i++ {
482482
if _, err := c.Channel(); err != nil {
483483
t.Fatalf("expected allocating all channel ids to succed, failed on %d with %v", i, err)
484484
}

0 commit comments

Comments
 (0)