Skip to content

Conversation

@Danielius1922
Copy link
Member

@Danielius1922 Danielius1922 commented Jun 5, 2025

Fixes #654

@coderabbitai
Copy link

coderabbitai bot commented Jun 5, 2025

Walkthrough

The changes reorder resource cleanup calls in cloud deregistration error handling and simplify event callback timer polling by removing an unnecessary variable and explicitly resetting a global pointer before callbacks. Additionally, message reference counting and deallocation are refactored to separate concerns, with related updates in CoAP message handling and OSCORE message processing. Minor code style refinements were made in IP adapter source files. TLS handshake retry logic and certificate addition were refactored for clarity. Dockerfiles were reformatted for readability and package order adjusted.

Changes

File(s) Change Summary
api/cloud/oc_cloud_deregister.c Swapped order of cloud_context_clear and oc_cloud_api_free_param in error handling branches.
api/oc_event_callback.c Removed next variable; directly accesses event_cb->next and resets a global pointer before callback invocation.
api/oc_message.c, api/oc_message_internal.h Added oc_message_refcount, oc_message_unref2, and oc_message_deallocate; refactored oc_message_unref to separate refcount decrement and deallocation.
messaging/coap/engine.c, messaging/coap/separate.c Replaced direct ref_count field access with oc_message_refcount(); replaced oc_message_unref() with oc_message_deallocate() for message cleanup after sending.
security/oc_oscore_engine.c Early exit if no OSCORE context; replaced boolean refcount tracking with oc_message_unref2(); switched to stack-allocated CoAP packet struct; restructured OSCORE message handling for clarity.
security/oc_tls.c Refactored check_retry_timers and oc_tls_add_new_certs for clearer control flow using early continues and reduced nesting.
port/android/ipadapter.c, port/esp32/adapter/src/ipadapter.c, port/linux/ip.c Refactored declaration and initialization of cmsg pointer in loops; minor style fixes without logic changes.
docker/apps/Dockerfile.cloud-server Reformatted cmake command invocation for readability, splitting long line into two.
docker/apps/Dockerfile.cloud-server-debug Swapped order of gcovr and g++ packages in apt-get install command.

Sequence Diagram(s)

sequenceDiagram
    participant CloudDeregister
    participant CloudContext
    participant ApiParam

    CloudDeregister->>CloudContext: clear (on error)
    CloudDeregister->>ApiParam: free (after context cleared)
Loading
sequenceDiagram
    participant EventCallbackPoll
    participant EventCallback
    participant GlobalPointer

    loop For each event callback
        EventCallbackPoll->>GlobalPointer: reset to NULL
        alt Timer expired
            EventCallbackPoll->>EventCallback: invoke callback
            EventCallbackPoll->>EventCallback: remove and free if needed
        else Timer not expired
            EventCallbackPoll->>EventCallback: continue to next
        end
    end
Loading
sequenceDiagram
    participant CoapEngine
    participant Message

    CoapEngine->>Message: oc_message_refcount()
    alt refcount == 0
        CoapEngine->>Message: oc_message_deallocate()
    else
        CoapEngine->>Message: retain message
    end
Loading
sequenceDiagram
    participant OSCOREEngine
    participant OSCOREContext
    participant Message
    participant CoapPacket

    OSCOREEngine->>OSCOREContext: find context for peer UUID
    alt no context
        OSCOREEngine->>OSCOREEngine: early exit to dispatch
    else
        OSCOREEngine->>Message: oc_message_unref2()
        alt message not deallocated
            OSCOREEngine->>CoapPacket: parse message (stack struct)
            OSCOREEngine->>OSCOREEngine: process request or response with partial IV handling
            OSCOREEngine->>Message: copy partial IV if needed
            OSCOREEngine->>OSCOREEngine: serialize and encrypt OSCORE message
        end
    end
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c69a248 and 5c08316.

📒 Files selected for processing (13)
  • api/cloud/oc_cloud_deregister.c (2 hunks)
  • api/oc_event_callback.c (1 hunks)
  • api/oc_message.c (2 hunks)
  • api/oc_message_internal.h (2 hunks)
  • docker/apps/Dockerfile.cloud-server (1 hunks)
  • docker/apps/Dockerfile.cloud-server-debug (1 hunks)
  • messaging/coap/engine.c (1 hunks)
  • messaging/coap/separate.c (1 hunks)
  • port/android/ipadapter.c (1 hunks)
  • port/esp32/adapter/src/ipadapter.c (1 hunks)
  • port/linux/ip.c (1 hunks)
  • security/oc_oscore_engine.c (1 hunks)
  • security/oc_tls.c (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • api/oc_event_callback.c
🚧 Files skipped from review as they are similar to previous changes (12)
  • docker/apps/Dockerfile.cloud-server
  • port/linux/ip.c
  • messaging/coap/separate.c
  • port/esp32/adapter/src/ipadapter.c
  • api/cloud/oc_cloud_deregister.c
  • api/oc_message_internal.h
  • port/android/ipadapter.c
  • docker/apps/Dockerfile.cloud-server-debug
  • messaging/coap/engine.c
  • security/oc_tls.c
  • api/oc_message.c
  • security/oc_oscore_engine.c
⏰ Context from checks skipped due to timeout of 90000ms (50)
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-tests (dtls-cloud-server-rep-realloc, -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON, -... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-dps-tests / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-dps-images (dps-cloud-server, Release, docker/apps/Dockerfile.dps-cloud-server) / build-and-push-image
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_UBSAN_ENABLED=ON, docker/apps/Dockerfile.dps-cloud-ser... / plgd-hub-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ocf-conformance-test-tool
Copy link

🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed.


ℹ️ To verify your latest change (b893536), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

@Danielius1922 Danielius1922 added OCF Conformance Testing OCF Conformance Testing required and removed OCF Conformance Testing OCF Conformance Testing required labels Jun 5, 2025
Fix issue 525174: Read from pointer after free in oc_cloud_deregister.c
Fix issue 525173: Read from pointer after free in oc_event_callback.c
Fix issue 525172: Read from pointer after free in oc_oscore_engine.c
@Danielius1922 Danielius1922 force-pushed the adam/feature/654-coverity-fixes-2 branch from c69a248 to 5c08316 Compare June 6, 2025 09:56
@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label Jun 6, 2025
@Danielius1922 Danielius1922 marked this pull request as ready for review June 6, 2025 09:57
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
35.8% Coverage on New Code (required ≥ 80%)
3.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@Danielius1922 Danielius1922 merged commit 49441ba into master Jun 6, 2025
187 of 189 checks passed
@Danielius1922 Danielius1922 deleted the adam/feature/654-coverity-fixes-2 branch June 6, 2025 11:21
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coverity issues

2 participants