public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Peter Radisson <radisson97@web.de>, 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: Fri, 28 Mar 2025 18:45:24 -0400	[thread overview]
Message-ID: <4fee13e3-d3d6-47be-87b8-d4303918cbaa@redhat.com> (raw)
In-Reply-To: <977a59f6-4e1e-4f7d-996d-8dbcd7a46794@web.de>

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.

> +
>   .PP
>   If the caller is not interested in the source address,
>   .I src_addr
> -- 
> 2.35.3
> 
> 
> 


-- 
Cheers,
Carlos.


  reply	other threads:[~2025-03-28 22:45 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 [this message]
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=4fee13e3-d3d6-47be-87b8-d4303918cbaa@redhat.com \
    --to=carlos@redhat.com \
    --cc=alx.manpages@gmail.com \
    --cc=alx@kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=radisson97@web.de \
    /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