Skip to content

Commit 1fc3a7b

Browse files
(gosec) Apply G115 fixes to x/mongo/driver/session package
Address gosec G115 integer overflow warnings in session handling
1 parent ea019e4 commit 1fc3a7b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

x/mongo/driver/session/client_session.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,10 @@ func (c *Client) StartTransaction(opts *TransactionOptions) error {
422422
// CheckCommitTransaction checks to see if allowed to commit transaction and returns
423423
// an error if not allowed.
424424
func (c *Client) CheckCommitTransaction() error {
425-
if c.TransactionState == None {
425+
switch c.TransactionState {
426+
case None:
426427
return ErrNoTransactStarted
427-
} else if c.TransactionState == Aborted {
428+
case Aborted:
428429
return ErrCommitAfterAbort
429430
}
430431
return nil
@@ -462,12 +463,12 @@ func (c *Client) UpdateCommitTransactionWriteConcern() {
462463
// CheckAbortTransaction checks to see if allowed to abort transaction and returns
463464
// an error if not allowed.
464465
func (c *Client) CheckAbortTransaction() error {
465-
switch {
466-
case c.TransactionState == None:
466+
switch c.TransactionState {
467+
case None:
467468
return ErrNoTransactStarted
468-
case c.TransactionState == Committed:
469+
case Committed:
469470
return ErrAbortAfterCommit
470-
case c.TransactionState == Aborted:
471+
case Aborted:
471472
return ErrAbortTwice
472473
}
473474
return nil
@@ -506,13 +507,14 @@ func (c *Client) ApplyCommand(desc description.Server) error {
506507
// Do not change state if committing after already committed
507508
return nil
508509
}
509-
if c.TransactionState == Starting {
510+
switch c.TransactionState {
511+
case Starting:
510512
c.TransactionState = InProgress
511513
// If this is in a transaction and the server is a mongos, pin it
512514
if desc.Kind == description.ServerKindMongos {
513515
c.PinnedServerAddr = &desc.Addr
514516
}
515-
} else if c.TransactionState == Committed || c.TransactionState == Aborted {
517+
case Committed, Aborted:
516518
c.TransactionState = None
517519
return c.clearTransactionOpts()
518520
}

0 commit comments

Comments
 (0)