mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
fix(touch): copy the connected list before editing it during deletion
DeleteWhich walked cssRaw.Get() while removing entries from cssAfter, which was the same slice header over the same backing array. After a non-tail removal the next touch saw the shifted list with a stale duplicate at the end: the same Which pointer was decremented twice or Disconnect ran on it, and cssAfter[:i] with the old length panicked with slice bounds out of range. Work on a copy and iterate that copy.
This commit is contained in:
1 file changed
+7
-3
@@ -12,8 +12,12 @@ func DeleteWhich(ws []*configure.Which) (err error) {
|
||||
// Sort touches to delete, placing larger indices first to delete from back to front
|
||||
data.SortSameTypeReverse()
|
||||
touches := data.Get()
|
||||
// cssAfter is edited in place below; take a copy so the removals do not
|
||||
// shift entries under the list being iterated (both used to alias the
|
||||
// same backing array, leaving a stale duplicate at the tail after a
|
||||
// non-tail removal and panicking on the next touch)
|
||||
cssRaw := configure.GetConnectedServers()
|
||||
cssAfter := cssRaw.Get()
|
||||
cssAfter := append([]*configure.Which(nil), cssRaw.Get()...)
|
||||
subscriptionsIndexes := make([]int, 0, len(ws))
|
||||
serversIndexes := make([]int, 0, len(ws))
|
||||
bDeletedSubscription := false
|
||||
@@ -23,7 +27,7 @@ func DeleteWhich(ws []*configure.Which) (err error) {
|
||||
switch v.TYPE {
|
||||
case configure.SubscriptionType: // Here a subscription is being deleted
|
||||
// Check if the currently connected node is in this subscription, if so, disconnect
|
||||
css := cssRaw.Get()
|
||||
css := cssAfter
|
||||
for i := len(css) - 1; i >= 0; i-- {
|
||||
cs := css[i]
|
||||
if cs != nil && cs.TYPE == configure.SubscriptionServerType {
|
||||
@@ -42,7 +46,7 @@ func DeleteWhich(ws []*configure.Which) (err error) {
|
||||
bDeletedSubscription = true
|
||||
case configure.ServerType:
|
||||
// Check if the currently connected node is this server, if so, disconnect
|
||||
css := cssRaw.Get()
|
||||
css := cssAfter
|
||||
for i := len(css) - 1; i >= 0; i-- {
|
||||
cs := css[i]
|
||||
if cs != nil && cs.TYPE == configure.ServerType {
|
||||
|
||||
Reference in new issue
Block a user