security: clear CodeQL findings (gmtime thread-safety + path-injection hardening) - #699
Merged
Conversation
…n hardening) Clears the 8 real CodeQL security alerts on frstrtr/c2pool. Triaged + independently re-reviewed: 1 CRITICAL is a genuine fix, 2 HIGH get defense-in-depth, 5 HIGH are getenv-rooted false positives (dismissed separately with justification). - #490 CRITICAL cpp/potentially-dangerous-function (src/core/log.cpp:163): std::gmtime returns a pointer into a shared static tm and is not reentrant. Replace with gmtime_r (POSIX) / gmtime_s (MSVC) into a local tm. Only gmtime/localtime call in src/. - #502/#503 HIGH cpp/path-injection (coin_peer_manager.hpp db_path()): m_symbol is a hardcoded ticker literal at every production ctor site (traced through all callers; no network->filename path exists), but add an alphanumeric-only guard so a future caller cannot inject a path component. Legitimate tickers (LTC/DOGE/DGB/DASH/BTC/NMC/...) are all alnum -> no on-disk filename change. - Rider: core::filesystem::config_path() dereferenced getenv() without a null check -> std::filesystem::path(nullptr) is UB if HOME/APPDATA is unset. Fall back to '.'. The other 5 path-injection alerts (#507 node.cpp:2199, #506/#505/#504 payout_manager.cpp:224/261/284, #501 auto_ratchet.hpp:309) all build a path from config_path() (getenv HOME/APPDATA) + a hardcoded basename, never from network/peer/miner input -> dismissed as false positive.
frstrtr
force-pushed
the
sec/codeql-gmtime-pathinj
branch
from
July 14, 2026 10:44
5b49c72 to
e910523
Compare
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.
Clears the 8 genuine CodeQL security alerts on the repo. The other ~92 open code-scanning alerts are code-quality notes (
cpp/loop-variable-changedfrom the intentionalargv[++i]arg-parsing, unused-var, etc.), not security — handled separately by dismiss/query-suite tuning. Dependabot = 0, secret-scanning = 0 (no dependency or secret vulns).Every finding was triaged, then independently re-reviewed (adversarial second pass) — both passes agree.
Fixed in this PR (3 findings)
src/core/log.cpp:163std::gmtime->gmtime_r/gmtime_sinto a localtm(reentrant). Only gmtime/localtime call insrc/.coin_peer_manager.hppdb_path()m_symbolbefore it enters the filenamecoin_peer_manager.hppdb_path()Rider (latent UB):
core::filesystem::config_path()dereferencedgetenv()with no null check ->path(nullptr)is UB ifHOME/APPDATAis unset. Now falls back to..Dismiss as false-positive (5 findings)
#507node.cpp:2199,#506/#505/#504payout_manager.cpp:224/261/284,#501auto_ratchet.hpp:309 - all build a path fromconfig_path()(getenvHOME/APPDATA) + a hardcoded basename literal, never from network/peer/miner input. Canonical CodeQL getenv-as-source FP; an attacker who controls$HOMEalready owns the process environment. Dismissed via the code-scanning API with that justification once this lands.Verification notes
m_symboltraced through every ctor caller: both productionCoinBroadcastersites pass either ablockchain_to_symbol()enum-switch literal or a--mergedspec gated behind an exact-matchget_chain_p2p_prefixwhitelist -> no../can reachdb_path(). The guard is pure defense-in-depth for future callers.chainparam, dashbroadcaster_fullport, and peer-address crawl data all independently ruled out as filename sources.