ntopng/include/flow_alerts
Ivan Nardi 8ee8b740ea
First batch of make cppcheck clean up (#10878)
Rework the `cppcheck:` recipe so it is usable in practice:
  - `--enable=all` -> `--enable=warning,performance,portability`
    (drops the `style`/`information`/`unusedFunction` groups, which produced
    hundreds of opinion-level hits)
  - drop `--force` (was re-analyzing every file once per #ifdef combination;
    single files took 40+ min). Analyzes the default build config only.
  - add `-j $(shell nproc)` + `--cppcheck-build-dir=.cppcheck-build` for
    parallelism and incremental caching; `mkdir -p` the cache dir in the recipe
  - suppress checks that are noise for this codebase:
      * useInitializationList  - micro perf, POD members
      * duplInheritedMember    - intentional non-virtual name shadowing
        (operator[], swap, enqueue, incUses, lua, ...)
      * noCopyConstructor / noOperatorEq - the flagged classes
        (NetworkInterface, Ntop, Flow, ...) are non-copyable by design and
        always held by pointer; the fix cppcheck suggests (add operator=)
        is meaningless for them
  - .gitignore: ignore the new .cppcheck-build/ cache directory

FlowAlertsLoader::registerRisk (src/FlowAlertsLoader.cpp)
  Missing `else`: `alert_to_risk[alert_type.id] = risk` was executed even when
  `alert_type.id >= MAX_DEFINED_FLOW_ALERT_TYPE` -> out-of-bounds array write.
  The sibling registerAlert() already had the `else`.

Uninitialized ndpi_protocol structs (src/NetworkInterface.cpp x6,
src/LuaEngineInterface.cpp x1)
  Local `ndpi_protocol` values were only partially initialized (proto.* set,
  but breed/fpc/state/category/custom_category_userdata left indeterminate)
  and then passed by value to get_ndpi_full_proto_name() /
  get_ndpi_proto_category(). Added `memset(&x, 0, sizeof(x))` at each
  declaration, matching the existing convention elsewhere in the tree.

Uninitialized locals
  - src/ParserInterface.cpp: `src2dst_direction` was read on the
    `flow == NULL` path (getFlow() not called). Initialize to a defined value;
    the value is not otherwise observable on that path.
  - include/Bitmap.h (toHexString): if `buf_len <= 0` the first loop never
    runs and `strlen(buf)` reads uninitialized memory; also `strlen(buf) - 2`
    underflows (unsigned) when the string is shorter than 2 bytes. Null-
    terminate up front and hoist strlen into a `size_t`, iterate with
    `pos + 2 < len`.

src/NetworkInterface.cpp incNumHosts()/decNumHosts()
  `if (isShuttingDown() || (!host->isUnicastHost())) return;` - the second
  term is always false, the function already returned on `!isUnicastHost()`
  a few lines above. Dropped it.

include/NetworkInterface.h getActiveFlowsStats()
  Declaration and definition disagreed on the first two parameter *names*
  (`stats, status_stats` vs `ndpi_stats, stats`); types matched. Renamed the
  header params to match the implementation.

No behavioural change; each argument was already non-negative.

  - Interface id (`get_id()` returns int; kept int because 3 call sites test
    `== -1`) formatted with %u in redis-key macros -> cast the argument
    `(u_int)` at the call site:
      include/AutonomousSystem.h, include/Country.h,
      include/ObservationPoint.h, include/VLAN.h,
      src/BroadcastDomains.cpp (x2), src/HostPools.cpp, src/LocalHost.cpp,
      src/LuaEngineInterface.cpp (x3), src/NetworkInterface.cpp (x2),
      src/SyslogParserInterface.cpp
  - src/HTTPserver.cpp: `%d` with get_http_port()/get_https_port() (u_int)
    -> `%u`; the scanf-width builder `"%%%u[^|]..."` fed `int` macros -> `%d`
  - src/Flow.cpp: `"%u.%u.%u.%u"` with `int` octets from a `%d` sscanf -> `%d`;
    `%u` (arg 13) with get_protocol_category() enum -> cast `(u_int)`
  - src/MacManufacturers.cpp: `int _mac[3]` scanned with `%02x`
    (wants `unsigned int*`) -> declare `u_int _mac[3]`
  - src/StatsManager.cpp: `%lu` with `static_cast<long int>(key)` epoch values
    -> `%ld` (respects the explicit signed cast)
  - src/Trace.cpp: `"%s.%u"` with loop `int i` / `i + 1` -> `%d`
  - src/Prefs.cpp: `%u` in usage() help text fed CONST_DEFAULT_* /
    MAX_NUM_* / CLICKHOUSE_MAX_* int macros -> cast `(u_int)`

std::string / std::vector parameters taken by value, changed to `const &`
(declaration and definition kept in sync; none are virtual or overrides, so
callers are source-compatible):

  - AggregatedFlowsStats::setInfoKey
  - Flow::setL7JSON
  - CustomFlowLuaScriptAlert::setAlertMessage
  - CustomHostLuaScriptAlert::setAlertMessage, ctor (_msg)
  - ScanRealtimeAlert ctor (_alerts, std::vector)
  - CustomHostLuaScript::allocAlert (_msg)
  - OtherAlertableEntity::getAlertCachedValue / setAlertCacheValue /
    triggerAlert / releaseAlert (key, value)
  - HostAlert::init and HostAlert(HostCheckID, ...) ctor (_check_name)
  - Ntop::luaFlowCheckInfo / luaHostCheckInfo (check_name)
  - Ntop::incBlacklisHits (listname)
  - Ntop::setLuaCache (key, val)
2026-09-01 08:36:01 +02:00
..
AccessControlListAlert.h Code format 2026-03-15 10:50:50 +01:00
BlacklistedClientContactAlert.h Code format 2026-03-15 10:50:50 +01:00
BlacklistedCountryAlert.h Code format 2026-03-15 10:50:50 +01:00
BlacklistedFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
BlacklistedServerContactAlert.h Code format 2026-03-15 10:50:50 +01:00
BroadcastNonUDPTrafficAlert.h Code format 2026-03-15 10:50:50 +01:00
CustomFlowLuaScriptAlert.h First batch of make cppcheck clean up (#10878) 2026-09-01 08:36:01 +02:00
DataExfiltrationAlert.h Code format 2026-03-15 10:50:50 +01:00
DeviceProtocolNotAllowedAlert.h Code format 2026-03-15 10:50:50 +01:00
DNSDataExfiltrationAlert.h Code format 2026-03-15 10:50:50 +01:00
ElephantFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
ExternalAlertCheckAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskBinaryApplicationTransferAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskClearTextCredentialsAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskDesktopOrFileSharingSessionAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskDNSFragmentedAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskDNSLargePacketAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskDNSSuspiciousTrafficAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskGenericAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskHTTPObsoleteServerAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskHTTPSuspiciousHeaderAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskHTTPSuspiciousURLAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskHTTPSuspiciousUserAgentAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskKnownProtocolOnNonStandardPortAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskMalformedPacketAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskMaliciousFingerprintAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskMaliciousSHA1CertificateAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskMalwareHostContactedAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskNumericIPHostAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskPeriodicFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskRiskyASNAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskRiskyDomainAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskSlowDoSAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskSMBInsecureVersionAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskSSHObsoleteClientAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskSSHObsoleteServerAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskSuspiciousDGADomainAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskSuspiciousEntropyAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSCertificateExpiredAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSCertificateMismatchAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSCertificateSelfSignedAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSCertValidityTooLongAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSFatalAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSMissingSNIAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSNotCarryingHTTPSAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSOldProtocolVersionAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSSuspiciousExtensionAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSUncommonALPNAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskTLSUnsafeCiphersAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskUnidirectionalTrafficAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskUnsafeProtocolAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskURLPossibleRCEInjectionAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskURLPossibleSQLInjectionAlert.h Code format 2026-03-15 10:50:50 +01:00
FlowRiskURLPossibleXSSAlert.h Code format 2026-03-15 10:50:50 +01:00
HostPolicyAlert.h Code format 2026-03-15 10:50:50 +01:00
IECInvalidCommandTransitionAlert.h Code format 2026-03-15 10:50:50 +01:00
IECInvalidTransitionAlert.h Code format 2026-03-15 10:50:50 +01:00
IECUnexpectedTypeIdAlert.h Code format 2026-03-15 10:50:50 +01:00
InvalidDNSQueryAlert.h Code format 2026-03-15 10:50:50 +01:00
LateralMovementAlert.h Code format 2026-03-15 10:50:50 +01:00
LongLivedFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
LowGoodputFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
ModbusInvalidTransitionAlert.h Code format 2026-03-15 10:50:50 +01:00
ModbusTooManyExceptionsAlert.h Code format 2026-03-15 10:50:50 +01:00
ModbusUnexpectedFunctionCodeAlert.h Code format 2026-03-15 10:50:50 +01:00
NedgeBlockedFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
NedgePolicyViolationAlert.h Code format 2026-03-15 10:50:50 +01:00
NotPurgedAlert.h Code format 2026-03-15 10:50:50 +01:00
PeriodicityChangedAlert.h Code format 2026-03-15 10:50:50 +01:00
ProfinetTooManyErrorsAlert.h Code format 2026-03-15 10:50:50 +01:00
QoEDegradedAlert.h Code format 2026-03-15 10:50:50 +01:00
RareDestinationAlert.h Code format 2026-03-15 10:50:50 +01:00
RemoteAccessAlert.h Code format 2026-03-15 10:50:50 +01:00
RemoteToLocalInsecureFlowAlert.h Code format 2026-03-15 10:50:50 +01:00
RemoteToRemoteAlert.h Code format 2026-03-15 10:50:50 +01:00
S7CommInvalidTransitionAlert.h Code format 2026-03-15 10:50:50 +01:00
S7CommTooManyErrorsAlert.h Code format 2026-03-15 10:50:50 +01:00
S7CommUnexpectedFunctionCodeAlert.h Code format 2026-03-15 10:50:50 +01:00
TCPConnectionNoAnswerAlert.h Code format 2026-03-15 10:50:50 +01:00
TCPFlowResetAlert.h Code format 2026-03-15 10:50:50 +01:00
TCPNoDataExchangedAlert.h Code format 2026-03-15 10:50:50 +01:00
TCPPacketsIssuesAlert.h Code format 2026-03-15 10:50:50 +01:00
TCPZeroWindowAlert.h Code format 2026-03-15 10:50:50 +01:00
UnexpectedDHCPServerAlert.h Code format 2026-03-15 10:50:50 +01:00
UnexpectedDNSServerAlert.h Code format 2026-03-15 10:50:50 +01:00
UnexpectedNTPServerAlert.h Code format 2026-03-15 10:50:50 +01:00
UnexpectedServerAlert.h Code format 2026-03-15 10:50:50 +01:00
UnexpectedSMTPServerAlert.h Code format 2026-03-15 10:50:50 +01:00
VLANBidirectionalTrafficAlert.h Code format 2026-03-15 10:50:50 +01:00
WebMiningAlert.h Code format 2026-03-15 10:50:50 +01:00