Skip to content

netutils: smtp: Treat recv EOF as an error#3600

Open
Old-Ding wants to merge 1 commit into
apache:masterfrom
Old-Ding:codex/smtp-recv-eof
Open

netutils: smtp: Treat recv EOF as an error#3600
Old-Ding wants to merge 1 commit into
apache:masterfrom
Old-Ding:codex/smtp-recv-eof

Conversation

@Old-Ding

@Old-Ding Old-Ding commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

recv() returns zero when the peer closes a TCP connection cleanly. The SMTP response path only treated negative returns as errors, so an EOF could leave stale or empty response data to be checked as if a server reply had arrived.

Return ERROR on zero-length receives at each SMTP response point.

Validation

  • git diff --check origin/master..HEAD
  • git show --check --stat --oneline HEAD
  • git ls-files --eol netutils/smtp/smtp.c

xiaoxiang781216
xiaoxiang781216 previously approved these changes Jul 6, 2026
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Old-Ding please fix:

../nuttx/tools/checkpatch.sh -c -u -m -g 4d5f60005c6d91c76e4a585fe3102aab50119ec6..HEAD
Error: /home/runner/work/nuttx-apps/nuttx-apps/apps/netutils/smtp/smtp.c:6:79: error: Long line found
Used config files:
    1: .codespellrc
Some checks failed. For contributing guidelines, see:
  https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md

Comment thread netutils/smtp/smtp.c

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @Old-Ding :-)

  • When no data received (recv() returns 0) do we want to return error are you sure? It looks there should be no processing but no error too? This looks like a functional change?
  • Please add valid email as git commit signature.

@Old-Ding

Old-Ding commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 0c9459b2: wrapped the long SPDX copyright line that checkpatch reported and added Signed-off-by to the follow-up commit. Both commits now use the same Old-Ding GitHub noreply identity.

For the recv() == 0 behavior: this function expects a required SMTP server reply before every next protocol step. A zero return from recv() means the peer performed an orderly shutdown, so no reply was received for that step. Treating that as ERROR keeps the transaction from continuing after EOF and avoids checking whatever was already in psmtp->buffer from an earlier reply.

@cederom

cederom commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@Old-Ding Old-Ding force-pushed the codex/smtp-recv-eof branch from 0c9459b to ab9dc07 Compare July 7, 2026 01:32
@Old-Ding

Old-Ding commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated in ab9dc070:

  • Amended the follow-up commit so it has a descriptive message body and Signed-off-by using the Old-Ding GitHub noreply address.
  • check, Lint, labeler, and the Build setup/select jobs are passing now; the remaining Build matrix jobs are still running/queued.

I do not have a local NuttX build/runtime environment on this Windows host (gcc, make, and cmake are not installed), so I am waiting for the GitHub Actions build logs. A runtime log still needs a real SMTP test environment; I have not attached one yet.

@cederom

cederom commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

"Old-Ding GitHub noreply address" is not a valid email address, please use email address that anyone can contact you when needed.

recv() returns zero when the peer closes the TCP connection cleanly. The SMTP response path only treated negative returns as errors, so EOF could leave stale or empty response data to be checked as if a server reply had arrived.

Return ERROR on zero-length receives at each SMTP response point and keep the SPDX copyright header within the project line length limit.

Signed-off-by: Old-Ding <ai.neo.ae86@gmail.com>
@Old-Ding Old-Ding force-pushed the codex/smtp-recv-eof branch from ab9dc07 to fc95721 Compare July 8, 2026 02:51
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.

4 participants