Skip to content

Commit eac7b5b

Browse files
(gosec) Apply G115 fixes to x/mongo/driver/auth package
Address gosec G115 integer overflow warnings in authentication: - Add SafeConvertNumeric for SASL token and buffer size conversions - Add SafeConvertNumeric for GSSAPI/SSPI buffer operations
1 parent d85a462 commit eac7b5b

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

x/mongo/driver/auth/gssapi.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

77
//go:build gssapi && (windows || linux || darwin)
8-
// +build gssapi
9-
// +build windows linux darwin
108

119
package auth
1210

x/mongo/driver/auth/gssapi_not_enabled.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

77
//go:build !gssapi
8-
// +build !gssapi
98

109
package auth
1110

x/mongo/driver/auth/gssapi_not_supported.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

77
//go:build gssapi && !windows && !linux && !darwin
8-
// +build gssapi,!windows,!linux,!darwin
98

109
package auth
1110

x/mongo/driver/auth/gssapi_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

77
//go:build gssapi
8-
// +build gssapi
98

109
package auth
1110

x/mongo/driver/auth/sasl.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212

1313
"go.mongodb.org/mongo-driver/v2/bson"
14+
"go.mongodb.org/mongo-driver/v2/internal/mathutil"
1415
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
1516
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
1617
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation"
@@ -127,9 +128,14 @@ func (sc *saslConversation) Finish(ctx context.Context, cfg *driver.AuthConfig,
127128
return nil
128129
}
129130

131+
cidI32, err := mathutil.SafeConvertNumeric[int32](cid)
132+
if err != nil {
133+
return fmt.Errorf("conversation ID %d is too large to encode: %w", cid, err)
134+
}
135+
130136
doc := bsoncore.BuildDocumentFromElements(nil,
131137
bsoncore.AppendInt32Element(nil, "saslContinue", 1),
132-
bsoncore.AppendInt32Element(nil, "conversationId", int32(cid)),
138+
bsoncore.AppendInt32Element(nil, "conversationId", cidI32),
133139
bsoncore.AppendBinaryElement(nil, "payload", 0x00, payload),
134140
)
135141
saslContinueCmd := operation.NewCommand(doc).

0 commit comments

Comments
 (0)