public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
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 18:47:44 +0100	[thread overview]
Message-ID: <977a59f6-4e1e-4f7d-996d-8dbcd7a46794@web.de> (raw)
In-Reply-To: <7cf47smc7ntz2k4rkekbuzehzymi3fnvwybsrn42pqgptm75wg@6s5b6mrwkhfv>



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

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
+.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



  reply	other threads:[~2025-03-27 17:47 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 [this message]
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=977a59f6-4e1e-4f7d-996d-8dbcd7a46794@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