Skip to content

Fix documentation and unreachable endpoint snapshot in Socket - #421

Merged
josesimoes merged 1 commit into
mainfrom
fix-sonar-smells
Sep 30, 2026
Merged

josesimoes merged 1 commit into
mainfrom
fix-sonar-smells

Conversation

@josesimoes

Copy link
Copy Markdown
Member

Description

  • SslStream
    • remove unnecessary boolean literals in Length/DataAvailable getters.
    • rename Read/Write parameter size → count to match Stream.
    • fix garbled Length/DataAvailable summaries and a typo.
  • Socket
    • add XML doc to finalizer.
    • fix ambiguous Send/Receive cref references.
  • Socket.ReceiveFrom: remove unreachable endpoint snapshot/store block; clarify comments.

Motivation and Context

  • Addresses code smells reported by SonarCloud on main after NetworkStream now rejects non-stream sockets #418.
  • ReceiveFrom block was dead code: _rightEndPoint is guaranteed non-null by the check at method entry, and native recvfrom always returns a new IPEndPoint. No behaviour change.
  • S2372 (exceptions thrown from Length/DataAvailable getters) not addressed: both are overrides and match .NET behaviour.

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

- SslStream
  + remove unnecessary boolean literals in Length/DataAvailable getters.
  + rename Read/Write parameter size → count to match Stream.
  + fix garbled Length/DataAvailable summaries and a typo.
- Socket
  + add XML doc to finalizer.
  + fix ambiguous Send/Receive cref references.
- Socket.ReceiveFrom: remove unreachable endpoint snapshot/store block; clarify comments.
@nfbot nfbot added the Type: enhancement New feature or request label Sep 30, 2026
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: nanoframework/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 03d397e7-e8da-477b-9200-a2e6b25d9d43

📥 Commits

Reviewing files that changed from the base of the PR and between 2af90bd and 580e42d.

📒 Files selected for processing (2)
  • nanoFramework.System.Net/Security/SslStream.cs
  • nanoFramework.System.Net/Sockets/Socket.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • SSL stream status properties now consistently report when the stream has been disposed.
    • ReceiveFrom now uses the endpoint supplied by the caller and returns the native receive result without an additional endpoint comparison.
  • Documentation

    • Clarified that SSL stream availability and length refer to decrypted data.

Walkthrough

The SSL stream updates clarify data descriptions, simplify disposed-state checks, and rename the Read and Write byte-count parameters. Socket.ReceiveFrom changes its binding requirement and endpoint handling. Socket XML documentation also changes.

Changes

SSL stream APIs

Layer / File(s) Summary
SSL stream data access and byte counts
nanoFramework.System.Net/Security/SslStream.cs
Length and DataAvailable descriptions now identify decrypted data, and disposed checks use if (_disposed). Read and Write use count as the byte-count parameter in validation and native I/O calls.

Socket APIs

Layer / File(s) Summary
ReceiveFrom endpoint handling and Socket documentation
nanoFramework.System.Net/Sockets/Socket.cs
ReceiveFrom documents and enforces a binding requirement, passes the caller’s endpoint to the native call, and returns its result. The Connected documentation references byte-array overloads, and the finalizer has XML summary documentation.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested labels: Type: documentation

Merge Risk: ⚪ Minimal · up to 580e4

The cleanup introduces no established merge-blocking failure. Positional SSL calls retain their behavior, and ReceiveFrom preserves its binding guard and native call. External callers using size: named arguments will need to use count:.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 580e4

The visible socket and TLS controls are preserved, and no newly introduced security weakness was demonstrated. Complete ReceiveFrom compatibility remains unconfirmed because the native endpoint-handling implementation was unavailable.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is to existing callers using these socket and SSL stream methods and their existing socket resources. The managed/native arguments and entry checks are unchanged; platform-native outcomes remain outside the assessed source coverage.

Trust Boundaries and Controls

  • observed — ReceiveFrom retains its disposed-handle and non-null socket-endpoint preconditions. SslStream retains buffer, disposal, offset, and count validation before its secure native read and write calls. The endpoint object still crosses the managed/native boundary by reference.

Resilience and Maintainability Implications

  • inferred — The deleted socket-endpoint assignment was redundant under the inspected managed lifecycle: Bind, Connect, and SendTo establish the field, and ReceiveFrom rejects a null field before native execution. This establishes managed state-store redundancy, not equivalence of native failure, interruption, concurrent, or repeated-call outcomes.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the Socket documentation updates and endpoint snapshot removal. It is longer than the preferred 50-character limit and omits the SslStream changes, but it remains concis…
Description check ✅ Passed The description clearly covers the SslStream and Socket changes, their motivation, and the reported testing status. It is related to the changeset.

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

Comment @coderabbitai help to get the list of available commands.

@josesimoes josesimoes changed the title Fix SonarCloud code smells in Socket and SslStream Fix documentation and unreachable endpoint snapshot in Socket Sep 30, 2026
@josesimoes
josesimoes merged commit a5c8676 into main Sep 30, 2026
9 of 10 checks passed
@josesimoes
josesimoes deleted the fix-sonar-smells branch September 30, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants