From: Peter Radisson <radisson97@web.de>
To: Carlos O'Donell <carlos@redhat.com>, 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: Sat, 29 Mar 2025 00:26:49 +0100 [thread overview]
Message-ID: <3f5eaef3-5751-4ff3-9d30-b67f11e9457f@web.de> (raw)
In-Reply-To: <4fee13e3-d3d6-47be-87b8-d4303918cbaa@redhat.com>
Am 28.03.25 um 23:45 schrieb Carlos O'Donell:
> On 3/27/25 1:47 PM, Peter Radisson wrote:
>> Am 27.03.25 um 18:28 schrieb Alejandro Colomar:
>>> On Thu, Mar 27, 2025 at 05:35:21PM +0100, Peter Radisson wrote:
>>>> V2:
>>>> * removed 1 empty line
>>>> * and changed wording to "content of" to make clear *addrlen is used.
>>
>> V3:
>> * changed wording:
>> less that null -> negativ
>
> s/negativ/negative/g
>
>>
>> thx for fast reply, unfortunately i noticed an other problem with the
>> page. I will report in an other mail.
>>
>>>> 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 9f464fde8dd168b71430ca29f631153e3e3fb2e5 Mon Sep 17 00:00:00 2001
>> From: Peter Radisson <--show-origin>
>> Date: Thu, 27 Mar 2025 18:39:29 +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..ba17d03a3 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 negativ the call will return with
>
> s/negativ/negative/g
>
>> +.IR EINVAL .
>> +If
>> +.I addrlen
>> +is less than sizeof struct sockaddr_in the src_addr will
>> +not be modified.
>
> My suggestion would be to place this as an entry under ERRORS
> for EINVAL.
>
> Adding all of this conditional text under recvfrom() seems overly
> complicated.
>
> We should document the success case and how it work for truncation.
>
IMHO is the error handling broken. Anything less that sizeof(struct
sockaddr_in) should cause an error. It does not so this behavier should
be documented here so everybody is aware about it.
(second thought: BUGS section ?)
ym2c
>> +
>> .PP
>> If the caller is not interested in the source address,
>> .I src_addr
>> --
>> 2.35.3
>>
>>
>>
>
>
prev parent reply other threads:[~2025-03-28 23:27 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
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 [this message]
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=3f5eaef3-5751-4ff3-9d30-b67f11e9457f@web.de \
--to=radisson97@web.de \
--cc=alx.manpages@gmail.com \
--cc=alx@kernel.org \
--cc=carlos@redhat.com \
--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