Skip to content

daemon: parse apid/ctid in dlt_daemon_control_set_log_level_v2#864

Open
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/set-log-level-v2-parse-apid-ctid
Open

daemon: parse apid/ctid in dlt_daemon_control_set_log_level_v2#864
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/set-log-level-v2-parse-apid-ctid

Conversation

@SoundMatt
Copy link
Copy Markdown

Problem

dlt_daemon_control_set_log_level_v2 never actually parsed the
apid / ctid fields out of incoming SET_LOG_LEVEL V2 requests:

  • req.apid / req.ctid (declared char * in
    DltServiceSetLogLevelV2) are zero-initialised to NULL.
  • The two dlt_set_id_v2() calls intended to populate them were
    no-ops because dlt_set_id_v2 early-returns when its destination is
    NULL.
  • Subsequent code at the wildcard / "apid only" / "ctid only" branches
    dereferences the still-NULL local apid / ctid
    (apid[apid_length - 1] etc.) when their length is non-zero,
    crashing the daemon.

Reachable from any client that can talk to the control socket
(dispatched from dlt_daemon_handle_control_messages_v2).

Full analysis in #863.

Fix

When each length field is non-zero, point req.apid / req.ctid
directly into msg->databuffer. Then assign the local apid / ctid
pointers via plain assignment so the existing branch logic (which keys
off apid == NULL / ctid == NULL) operates on real values.

req shares storage with the message buffer only for the duration of
this function call, so the pointer-into-databuffer trick is lifetime-
safe.

Notes

  • This PR is independent of daemon: fix out-of-bounds read in dlt_daemon_control_set_log_level_v2 #862 (the OOB-read fix in the same
    function): they touch overlapping lines but not in conflicting
    ways. Whichever lands first, the other rebases trivially.
  • I have not added a unit test because the function is exercised only
    end-to-end with a live daemon and crafted control messages. Happy to
    add one if maintainers can point me at the right harness.

Closes #863.

The function never assigned req.apid or req.ctid, so the SET_LOG_LEVEL
V2 control handler never actually parsed the apid/ctid fields out of
the message. The two pre-existing dlt_set_id_v2() calls (filling
req.apid / req.ctid, then filling local apid / ctid from req) were
no-ops because:

- req is zero-initialised (DltServiceSetLogLevelV2 req = {0};), so
  req.apid and req.ctid (declared as char * in the struct) start NULL.
- dlt_set_id_v2 early-returns when its destination id is NULL.

Consequences:

- Requests with apidlen = ctidlen = 0 fell through to the else branch
  with apid = ctid = NULL, silently no-op'ing.
- Requests with apidlen != 0 dereferenced the still-NULL local apid at
  the wildcard / "field-only" branches (apid[apid_length - 1]),
  crashing the daemon. Reachable from any client that can speak to the
  control socket.

Fix: when each length field is non-zero, point req.apid / req.ctid
directly into msg->databuffer (lifetime is bounded by this function's
stack frame). Then assign the local apid / ctid via plain pointer
assignment so the existing wildcard / field-only branch logic (which
keys off apid == NULL / ctid == NULL) operates on real values.

Closes COVESA#863.
SoundMatt added a commit to SoundMatt/dlt-daemon that referenced this pull request May 5, 2026
Companion fix to the OOB-read fix in this same commit series. The
function never assigned req->apid or req->ctid: req is calloc'd, so
the char * pointer fields start NULL, and the dlt_set_id_v2(req->apid,
...) call to populate them was a no-op (dlt_set_id_v2 early-returns
when its destination is NULL). req->apid / req->ctid stayed NULL and
were then passed to dlt_daemon_application_find_v2 and
dlt_daemon_context_find_v2 despite req->apidlen / req->ctidlen being
non-zero — every non-empty lookup was silently turned into a
zero-length one.

Replace the no-op dlt_set_id_v2 calls with conditional pointer
assignments into msg->databuffer, mirroring the surgical approach
taken for set_log_level_v2 in PR COVESA#864 and unregister_context_v2 in
PR COVESA#868. The bounds checks added in the previous commit ensure the
pointer-into-databuffer assignments are safe.

Closes COVESA#870.
Related: COVESA#866.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dlt_daemon_control_set_log_level_v2 never assigns req.apid/req.ctid; silently fails or crashes the daemon

1 participant