Skip to content

Commit e43fe38

Browse files
committedFeb 4, 2025
qrchan: clone code list before using
Closes tulir#725
1 parent a75587a commit e43fe38

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎qrchan.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package whatsmeow
88

99
import (
1010
"context"
11+
"slices"
1112
"sync"
1213
"sync/atomic"
1314
"time"
@@ -58,10 +59,10 @@ type qrChannel struct {
5859
stopQRs chan struct{}
5960
}
6061

61-
func (qrc *qrChannel) emitQRs(evt *events.QR) {
62+
func (qrc *qrChannel) emitQRs(codes []string) {
6263
var nextCode string
6364
for {
64-
if len(evt.Codes) == 0 {
65+
if len(codes) == 0 {
6566
if atomic.CompareAndSwapUint32(&qrc.closed, 0, 1) {
6667
qrc.log.Debugf("Ran out of QR codes, closing channel with status %s and disconnecting client", QRChannelTimeout)
6768
qrc.output <- QRChannelTimeout
@@ -77,10 +78,10 @@ func (qrc *qrChannel) emitQRs(evt *events.QR) {
7778
return
7879
}
7980
timeout := 20 * time.Second
80-
if len(evt.Codes) == 6 {
81+
if len(codes) == 6 {
8182
timeout = 60 * time.Second
8283
}
83-
nextCode, evt.Codes = evt.Codes[0], evt.Codes[1:]
84+
nextCode, codes = codes[0], codes[1:]
8485
qrc.log.Debugf("Emitting QR code %s", nextCode)
8586
select {
8687
case qrc.output <- QRChannelItem{Code: nextCode, Timeout: timeout, Event: QRChannelEventCode}:
@@ -118,7 +119,7 @@ func (qrc *qrChannel) handleEvent(rawEvt interface{}) {
118119
switch evt := rawEvt.(type) {
119120
case *events.QR:
120121
qrc.log.Debugf("Received QR code event, starting to emit codes to channel")
121-
go qrc.emitQRs(evt)
122+
go qrc.emitQRs(slices.Clone(evt.Codes))
122123
return
123124
case *events.QRScannedWithoutMultidevice:
124125
qrc.log.Debugf("QR code scanned without multidevice enabled")

0 commit comments

Comments
 (0)
Please sign in to comment.