Fix security vulnerabilities, race conditions, panics, and logic bugs#2
Draft
Copilot wants to merge 6 commits into
Draft
Fix security vulnerabilities, race conditions, panics, and logic bugs#2Copilot wants to merge 6 commits into
Copilot wants to merge 6 commits into
Conversation
- Fix CloseChannelWithoutPanic to actually close channel instead of only on panic - Replace panic with log in TryExpandError for unexpected reflect.Kind - Fix file descriptor leak in NewMTProto by closing file after permission check - Increase notification timeout from 1ms to 100ms to prevent dropped messages - Remove defer inside loop in handleRawUpdate (defer only runs on function exit) - Fix data race in UpdatePeersToCache by holding RLock when reading cache sizes - Fix race condition in albumBox.WaitAndTrigger by copying handlers map under lock - Fix nil pointer dereference in tcpConn.Read for io.ErrClosedPipe handling - Fix nil pointer dereference in cleanupIdleSenders by checking sender != nil - Add retry limit to auth key generation to prevent unbounded recursion - Improve stop channel handling in Start/St to prevent goroutine leaks Co-authored-by: Praveenkumar801 <131750384+Praveenkumar801@users.noreply.github.com>
- Fix error variable usage in permission check error message - Remove redundant makeAuthKeyInternal function Co-authored-by: Praveenkumar801 <131750384+Praveenkumar801@users.noreply.github.com>
- Add nil check to CloseChannelWithoutPanic to prevent panic on nil channel - Add mutex-protected resetStopChannel helper for thread-safe channel management - Deep copy handler slices in WaitAndTrigger to prevent race conditions Co-authored-by: Praveenkumar801 <131750384+Praveenkumar801@users.noreply.github.com>
Only recover from "close of closed channel" panics, re-panic for other unexpected panic types to avoid masking programming errors. Co-authored-by: Praveenkumar801 <131750384+Praveenkumar801@users.noreply.github.com>
Only recover from exact "close of closed channel" panic message to avoid suppressing other legitimate panics. Co-authored-by: Praveenkumar801 <131750384+Praveenkumar801@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Analyze for security issues, deadlocks, and logic errors
Fix security vulnerabilities, race conditions, panics, and logic bugs
Nov 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Analysis of the codebase revealed multiple security and reliability issues including race conditions, nil pointer dereferences, resource leaks, unbounded recursion, and incorrect concurrency patterns.
Fixes
Concurrency Issues
telegram/cache.go): Accessed map sizes without holding locktelegram/updates.go): Iterated dispatcher handlers without lock; now deep copies under RLocktelegram/client.go): Added mutex-protectedresetStopChannel()to prevent goroutine leaksNil Pointer Dereferences
internal/transport/connection.go): Fixed logic that could deref nile.Errwhen checking forio.ErrClosedPipetelegram/client.go): Added nil check before accessingsender.GetLastUsedTime()Resource Leaks
mtproto.go):os.OpenFilewas never closed during permission checkPanic Prevention
internal/utils/sync.go): Function never actually closed channel; now closes with specific panic recoveryerrors.go): Replacedpanic()with log on unexpected reflect.KindLogic Bugs
telegram/updates.go): Removed defer in loop (defer runs on function exit, not iteration end)mtproto.go): Increased from 1ms to 100ms to prevent dropped messageshandshake.go): Auth key generation could recurse infinitely; added 3-retry limitExample Fix
CodeQL scan shows no security alerts.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.