Skip to content

Fix NULL dereference when serializing/measuring a tag with no item set#420

Merged
PJK merged 3 commits intomasterfrom
fix/tag-null-item-crashes
Apr 6, 2026
Merged

Fix NULL dereference when serializing/measuring a tag with no item set#420
PJK merged 3 commits intomasterfrom
fix/tag-null-item-crashes

Conversation

@PJK
Copy link
Copy Markdown
Owner

@PJK PJK commented Apr 3, 2026

Fixes #416.

Summary

Commit e87cc36 changed cbor_tag_item() to return NULL when called on a tag with no item set, but several call sites using cbor_move(cbor_tag_item(...)) were not updated. Since cbor_move unconditionally does item->refcount--, passing NULL causes an immediate crash.

  • cbor_move (common.c): added NULL guard — returns NULL when passed NULL. This makes the cbor_move(cbor_tag_item(...)) pattern safe by contract.
  • cbor_serialized_size (serialization.c): extract cbor_tag_item result into a local, return 0 if NULL before calling cbor_move.
  • cbor_serialize_tag (serialization.c): same — return 0 (serialization failure) if the tag has no item set.

Test plan

  • test_move_nullcbor_move(cbor_tag_item(empty_tag)) returns NULL without crashing
  • test_serialized_size_tag_no_itemcbor_serialized_size returns 0 for a tag with no item
  • test_serialize_tag_no_itemcbor_serialize returns 0 for a tag with no item
  • Full test suite (28 targets) passes

🤖 Generated with Claude Code

PJK and others added 2 commits April 4, 2026 01:02
cbor_tag_item() returns NULL when no item has been set on a tag (since
e87cc36), but call sites using cbor_move(cbor_tag_item(...)) were not
updated, causing a NULL dereference in cbor_move.

- cbor_move: guard against NULL input, returning NULL
- cbor_serialized_size: extract cbor_tag_item result, return 0 if NULL
- cbor_serialize_tag: same, return 0 (serialization failure) if no item

Fixes #416

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.82%. Comparing base (2a7b001) to head (7e3c481).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #420   +/-   ##
=======================================
  Coverage   99.82%   99.82%           
=======================================
  Files          20       20           
  Lines        1757     1762    +5     
=======================================
+ Hits         1754     1759    +5     
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PJK PJK merged commit 90d5771 into master Apr 6, 2026
19 checks passed
@PJK PJK deleted the fix/tag-null-item-crashes branch April 6, 2026 19:35
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.

[Security] NULL pointer dereference in cbor_serialized_size() and cbor_serialize_tag() via cbor_move(cbor_tag_item())

1 participant