From: Peter Radisson <radisson97@web.de>
To: Alejandro Colomar <alx@kernel.org>
Cc: linux-man@vger.kernel.org,
"Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
Subject: Re: fix: recvfrom() error handling
Date: Thu, 27 Mar 2025 17:35:21 +0100 [thread overview]
Message-ID: <86f7516b-ba85-4737-9a63-951aabf3f681@web.de> (raw)
In-Reply-To: <ryuuydac7ybjw4pxiqzrjokcwvds3a6ezbjdi6h5fbz7zbr5d7@cqk5eio4lyrh>
V2:
* removed 1 empty line
* and changed wording to "content of" to make clear *addrlen is used.
To replicate the problem:
// intended use
struct sockaddr_in sock_out;
int slen=sizeof(sock_out); //socklen_t
recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &sock_out,
&slen);
// error case
struct sockaddr_in sock_out;
int slen=1;
recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &sock_out,
&slen);
funfact: this escapes the error handling in the linux kernel (no crash)
set slen=-1 and you get EINVAL.
hope that helps.
From 056b50b50dca9f08d203d1d56fdcb6e84d228dba Mon Sep 17 00:00:00 2001
From: Peter Radisson <--show-origin>
Date: Thu, 27 Mar 2025 17:05:51 +0100
Subject: [PATCH] Be more verbose about recvfrom(2) error handling
Signed-off-by: Peter Radisson <--show-origin>
---
man2/recv.2 | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/man2/recv.2 b/man2/recv.2
index 2659957a6..413c42271 100644
--- a/man2/recv.2
+++ b/man2/recv.2
@@ -293,6 +293,22 @@ The returned address is truncated if the buffer
provided is too small;
in this case,
.I addrlen
will return a value greater than was supplied to the call.
+If
+.I src_addr
+is NULL
+.I addrlen
+will be ignored.
+If
+.I src_addr
+is not NULL and the content of
+.I addrlen
+is less than null the call will return with
+.IR EINVAL .
+If
+.I addrlen
+is less than sizeof struct sockaddr_in the src_addr will
+not be modified.
+
.PP
If the caller is not interested in the source address,
.I src_addr
--
2.35.3
next prev parent reply other threads:[~2025-03-27 16:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 10:55 fix: recvfrom() error handling Peter Radisson
2025-03-27 12:29 ` Alejandro Colomar
2025-03-27 16:35 ` Peter Radisson [this message]
2025-03-27 17:28 ` Alejandro Colomar
2025-03-27 17:47 ` Peter Radisson
2025-03-28 22:45 ` Carlos O'Donell
2025-03-28 23:26 ` Peter Radisson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86f7516b-ba85-4737-9a63-951aabf3f681@web.de \
--to=radisson97@web.de \
--cc=alx.manpages@gmail.com \
--cc=alx@kernel.org \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox