Skip to content

Fix Coverity static analysis warnings#4920

Merged
nanangizz merged 1 commit intomasterfrom
fix/coverity-warnings
Apr 15, 2026
Merged

Fix Coverity static analysis warnings#4920
nanangizz merged 1 commit intomasterfrom
fix/coverity-warnings

Conversation

@nanangizz
Copy link
Copy Markdown
Member

@nanangizz nanangizz commented Apr 15, 2026

Summary

Address multiple Coverity Scan findings across pjlib, pjlib-util, pjmedia, pjnath, and pjsip:

  • UNINIT (7 CIDs): Zero-initialize chal_param struct in all pjsip_auth_clt_async_impl_on_challenge() call sites so user_data is not left uninitialized
  • LOCK_EVASION: Move Opus codec output frame writes before mutex unlock in codec_decode(), consistent with other return paths
  • NO_EFFECT: Use #if preprocessor guard for PJ_SSL_SEND_OP_ACTIVE_MAX check, eliminating unsigned->=0 tautology at default value
  • SLEEP: Release mutex before pj_ioqueue_unregister() in ioqueue unregister test callback to avoid potential blocking under lock
  • TAINTED_SCALAR (2 CIDs): Add explicit payload length bounds in WebSocket frame decoders (test + production)
  • CHECKED_RETURN (4 CIDs): Check pjlib_util_init()/pjnath_init() return values in sample apps and pjturn-srv. In strerror.c, return values are cast to (void) instead — this sample intentionally continues on partial init failure since its purpose is translating error codes and partial initialization still covers other error ranges.

Not addressed (false positives)

  • WRAPPER_ESCAPE (5 CIDs): unique_ptr<TestAccount> correctly manages Account lifetime via RAII destructor
  • REVERSE_INULL (1 CID): udp is always non-NULL at dereference point; null check at cleanup is defensive for goto pattern

Test plan

  • Build passes (zero errors, zero new warnings)
  • CI

Co-Authored-By: Claude Code

Address static analysis findings from Coverity Scan:

- UNINIT (CID 1645659/58/56/55/52/49/48/45/41): Zero-initialize
  chal_param in all pjsip_auth_clt_async_impl_on_challenge() callers
  so user_data field is not left uninitialized.

- LOCK_EVASION (CID 1654278): Move opus codec output frame writes
  before mutex unlock in codec_decode() for consistency with other
  return paths.

- NO_EFFECT (CID 1654265): Use #if preprocessor guard instead of
  runtime check for PJ_SSL_SEND_OP_ACTIVE_MAX, eliminating tautology
  when the macro is 0 (default).

- SLEEP (CID 1654159): Release mutex before pj_ioqueue_unregister()
  in ioqueue unregister test callback.

- TAINTED_SCALAR (CID 1654788): Cap decoded payload length against
  buffer size in websock_test server_decode_frame().

- TAINTED_SCALAR (CID 1239025): Add explicit payload_len bound check
  in websock decode_frame_header() for static analysis.

- CHECKED_RETURN (CID 1645787/86/85/84): Check pjlib_util_init() and
  pjnath_init() return values in sample apps and pjturn-srv.

Co-Authored-By: Claude Code
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses multiple Coverity static analysis findings across the SIP stack, media codec, SSL socket code, WebSocket framing, tests, and sample applications to improve correctness and avoid flagged patterns.

Changes:

  • Zero-initialize pjsip_auth_clt_async_on_chal_param at async-auth challenge call sites to avoid copying uninitialized fields.
  • Adjust locking/order-of-operations to avoid Coverity concurrency findings (Opus decode output writes; ioqueue unregister callback).
  • Add bounds checks / preprocessor guards and improve return-value handling in select utilities, tests, and sample apps.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pjsip/src/pjsua-lib/pjsua_im.c Zero-initialize async auth challenge param in IM callbacks.
pjsip/src/pjsip/sip_dialog.c Zero-initialize async auth challenge param in dialog response handler.
pjsip/src/pjsip-ua/sip_reg.c Zero-initialize async auth challenge param in regc transaction callback.
pjsip/src/pjsip-ua/sip_inv.c Zero-initialize async auth challenge param across INVITE-related challenge handlers.
pjsip/src/pjsip-simple/publishc.c Zero-initialize async auth challenge param in PUBLISH client handler.
pjsip/src/pjsip-simple/evsub.c Zero-initialize async auth challenge param in event subscription handlers.
pjsip-apps/src/samples/strerror.c Changes handling of init return values (currently explicitly ignored).
pjsip-apps/src/samples/httpdemo.c Check pj_init() and pjlib_util_init() return values.
pjsip-apps/src/samples/clidemo.c Check pj_init() and pjlib_util_init() return values.
pjnath/src/pjturn-srv/main.c Check pjlib_util_init() / pjnath_init() return values.
pjmedia/src/pjmedia-codec/opus.c Write to output before unlocking mutex on the “buffer first packet” path.
pjlib/src/pjlib-test/ioq_unreg.c Unlock mutex before calling pj_ioqueue_unregister() in callback.
pjlib/src/pj/ssl_sock_imp_common.c Replace tautological runtime check with #if PJ_SSL_SEND_OP_ACTIVE_MAX > 0.
pjlib-util/src/pjlib-util/websock.c Add explicit payload length cap check in frame decode helper.
pjlib-util/src/pjlib-util-test/websock_test.c Add explicit payload length cap in test frame decoder.

Comment thread pjsip-apps/src/samples/strerror.c
@nanangizz nanangizz marked this pull request as ready for review April 15, 2026 07:41
@nanangizz nanangizz requested a review from sauwming April 15, 2026 07:42
@nanangizz nanangizz merged commit 2cf88a5 into master Apr 15, 2026
57 of 58 checks passed
@nanangizz nanangizz deleted the fix/coverity-warnings branch April 15, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants