* fix: recvfrom() error handling @ 2025-03-27 10:55 Peter Radisson 2025-03-27 12:29 ` Alejandro Colomar 0 siblings, 1 reply; 7+ messages in thread From: Peter Radisson @ 2025-03-27 10:55 UTC (permalink / raw) To: linux-man; +Cc: Alejandro Colomar (man-pages) Hello List, while chasing an unrelated bug i found the description of recvfrom() was missing some error description. I would suggest to add a few lines to make this confusing state more clear. CU --- recv.2.org 2025-03-25 21:55:10.914273000 +0100 +++ recv.2 2025-03-25 22:55:18.843789307 +0100 @@ -299,6 +299,23 @@ and .I addrlen should be specified as NULL. +If +.I src_addr +is NULL +.I addrlen +will be ignored. + +If +.I src_addr +is not NULL and +.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. + .\" .SS recv() The ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: fix: recvfrom() error handling 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 0 siblings, 1 reply; 7+ messages in thread From: Alejandro Colomar @ 2025-03-27 12:29 UTC (permalink / raw) To: Peter Radisson; +Cc: linux-man, Alejandro Colomar (man-pages) [-- Attachment #1: Type: text/plain, Size: 1639 bytes --] Hi Peter, On Thu, Mar 27, 2025 at 11:55:43AM +0100, Peter Radisson wrote: > Hello List, > while chasing an unrelated bug i found the description of recvfrom() > was missing some error description. I would suggest to add a few lines > to make this confusing state more clear. > > CU > > --- recv.2.org 2025-03-25 21:55:10.914273000 +0100 > +++ recv.2 2025-03-25 22:55:18.843789307 +0100 Could you please use git-format-patch(1)? > @@ -299,6 +299,23 @@ > and > .I addrlen > should be specified as NULL. > +If > +.I src_addr > +is NULL > +.I addrlen > +will be ignored. > + Please don't use blank lines in man(7) source. Use paragraphing macros (.P is for a normal paragraph, and .IP is an indented paragraph). > +If > +.I src_addr > +is not NULL and > +.I addrlen > +is less than null the call will return with What do you mean by "less than null"? Pointers don't have a sign, so it's not possible to have a pointer be less than null. alx@devuan:~/tmp$ cat p.c int main(void) { void *p = (void *) -1; return p < (void *) 0; } alx@devuan:~/tmp$ gcc -Wall -Wextra -Wtautological-compare p.c p.c: In function ‘main’: p.c:6:18: warning: ordered comparison of pointer with null pointer [-Wextra] 6 | return p < (void *) 0; | ^ alx@devuan:~/tmp$ ./a.out alx@devuan:~/tmp$ echo $? 0 Have a lovely day! Alex > +.IR EINVAL . > +If > +.I addrlen > +is less than sizeof struct sockaddr_in the src_addr will > +not be modified. > + > .\" > .SS recv() > The > -- <https://www.alejandro-colomar.es/> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: fix: recvfrom() error handling 2025-03-27 12:29 ` Alejandro Colomar @ 2025-03-27 16:35 ` Peter Radisson 2025-03-27 17:28 ` Alejandro Colomar 0 siblings, 1 reply; 7+ messages in thread From: Peter Radisson @ 2025-03-27 16:35 UTC (permalink / raw) To: Alejandro Colomar; +Cc: linux-man, Alejandro Colomar (man-pages) 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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: fix: recvfrom() error handling 2025-03-27 16:35 ` Peter Radisson @ 2025-03-27 17:28 ` Alejandro Colomar 2025-03-27 17:47 ` Peter Radisson 0 siblings, 1 reply; 7+ messages in thread From: Alejandro Colomar @ 2025-03-27 17:28 UTC (permalink / raw) To: Peter Radisson; +Cc: linux-man, Alejandro Colomar (man-pages) [-- Attachment #1: Type: text/plain, Size: 1990 bytes --] 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. > > 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 Hi Peter, An integer cannot be compared to null. Do you mean zero? You could rewrite it as and .I addrlen is negative, ... Cheers, Alex > +.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 > > > -- <https://www.alejandro-colomar.es/> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: fix: recvfrom() error handling 2025-03-27 17:28 ` Alejandro Colomar @ 2025-03-27 17:47 ` Peter Radisson 2025-03-28 22:45 ` Carlos O'Donell 0 siblings, 1 reply; 7+ messages in thread From: Peter Radisson @ 2025-03-27 17:47 UTC (permalink / raw) To: Alejandro Colomar; +Cc: linux-man, Alejandro Colomar (man-pages) 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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: fix: recvfrom() error handling 2025-03-27 17:47 ` Peter Radisson @ 2025-03-28 22:45 ` Carlos O'Donell 2025-03-28 23:26 ` Peter Radisson 0 siblings, 1 reply; 7+ messages in thread From: Carlos O'Donell @ 2025-03-28 22:45 UTC (permalink / raw) To: Peter Radisson, Alejandro Colomar Cc: linux-man, Alejandro Colomar (man-pages) 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. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: fix: recvfrom() error handling 2025-03-28 22:45 ` Carlos O'Donell @ 2025-03-28 23:26 ` Peter Radisson 0 siblings, 0 replies; 7+ messages in thread From: Peter Radisson @ 2025-03-28 23:26 UTC (permalink / raw) To: Carlos O'Donell, Alejandro Colomar Cc: linux-man, Alejandro Colomar (man-pages) 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 >> >> >> > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-03-28 23:27 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox