[hurd,commited] socket: Fix tst-cmsghdr-skeleton.c use of cmsg_len
Checks
Commit Message
cmsg_len is supposed to be socklen_t according to standards, but it was made
size_t on Linux, see BZ 16919. For ports that have it socklen_t, SIZE_MAX is
too large. We can however explicitly cast it to the type of cmsg_len so it
will fit according to that type.
---
socket/tst-cmsghdr-skeleton.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mai 01 2023, Samuel Thibault wrote:
> cmsg_len is supposed to be socklen_t according to standards, but it was made
> size_t on Linux, see BZ 16919. For ports that have it socklen_t, SIZE_MAX is
> too large. We can however explicitly cast it to the type of cmsg_len so it
> will fit according to that type.
> ---
> socket/tst-cmsghdr-skeleton.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/socket/tst-cmsghdr-skeleton.c b/socket/tst-cmsghdr-skeleton.c
> index 296a0a8581..9516139f87 100644
> --- a/socket/tst-cmsghdr-skeleton.c
> +++ b/socket/tst-cmsghdr-skeleton.c
> @@ -49,7 +49,7 @@ RUN_TEST_FUNCNAME (CMSG_NXTHDR_IMPL) (void)
> /* The first header length is so big, using it would cause an overflow. */
> cmsg = CMSG_FIRSTHDR (&m);
> TEST_VERIFY_EXIT ((char *) cmsg == cmsgbuf);
> - cmsg->cmsg_len = SIZE_MAX;
> + cmsg->cmsg_len = (__typeof (cmsg->cmsg_len)) SIZE_MAX;
What does that fix?
Andreas Schwab, le lun. 01 mai 2023 15:38:45 +0200, a ecrit:
> On Mai 01 2023, Samuel Thibault wrote:
>
> > cmsg_len is supposed to be socklen_t according to standards, but it was made
> > size_t on Linux, see BZ 16919. For ports that have it socklen_t, SIZE_MAX is
> > too large. We can however explicitly cast it to the type of cmsg_len so it
> > will fit according to that type.
> > ---
> > socket/tst-cmsghdr-skeleton.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/socket/tst-cmsghdr-skeleton.c b/socket/tst-cmsghdr-skeleton.c
> > index 296a0a8581..9516139f87 100644
> > --- a/socket/tst-cmsghdr-skeleton.c
> > +++ b/socket/tst-cmsghdr-skeleton.c
> > @@ -49,7 +49,7 @@ RUN_TEST_FUNCNAME (CMSG_NXTHDR_IMPL) (void)
> > /* The first header length is so big, using it would cause an overflow. */
> > cmsg = CMSG_FIRSTHDR (&m);
> > TEST_VERIFY_EXIT ((char *) cmsg == cmsgbuf);
> > - cmsg->cmsg_len = SIZE_MAX;
> > + cmsg->cmsg_len = (__typeof (cmsg->cmsg_len)) SIZE_MAX;
>
> What does that fix?
64bit hurd, where cmsg_len is socklen_t as the standards require (thus
32bit).
Samuel
On Mai 01 2023, Samuel Thibault wrote:
> Andreas Schwab, le lun. 01 mai 2023 15:38:45 +0200, a ecrit:
>> On Mai 01 2023, Samuel Thibault wrote:
>>
>> > cmsg_len is supposed to be socklen_t according to standards, but it was made
>> > size_t on Linux, see BZ 16919. For ports that have it socklen_t, SIZE_MAX is
>> > too large. We can however explicitly cast it to the type of cmsg_len so it
>> > will fit according to that type.
>> > ---
>> > socket/tst-cmsghdr-skeleton.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/socket/tst-cmsghdr-skeleton.c b/socket/tst-cmsghdr-skeleton.c
>> > index 296a0a8581..9516139f87 100644
>> > --- a/socket/tst-cmsghdr-skeleton.c
>> > +++ b/socket/tst-cmsghdr-skeleton.c
>> > @@ -49,7 +49,7 @@ RUN_TEST_FUNCNAME (CMSG_NXTHDR_IMPL) (void)
>> > /* The first header length is so big, using it would cause an overflow. */
>> > cmsg = CMSG_FIRSTHDR (&m);
>> > TEST_VERIFY_EXIT ((char *) cmsg == cmsgbuf);
>> > - cmsg->cmsg_len = SIZE_MAX;
>> > + cmsg->cmsg_len = (__typeof (cmsg->cmsg_len)) SIZE_MAX;
>>
>> What does that fix?
>
> 64bit hurd, where cmsg_len is socklen_t as the standards require (thus
> 32bit).
And what does it fix?
Andreas Schwab, le lun. 01 mai 2023 16:03:32 +0200, a ecrit:
> On Mai 01 2023, Samuel Thibault wrote:
>
> > Andreas Schwab, le lun. 01 mai 2023 15:38:45 +0200, a ecrit:
> >> On Mai 01 2023, Samuel Thibault wrote:
> >>
> >> > cmsg_len is supposed to be socklen_t according to standards, but it was made
> >> > size_t on Linux, see BZ 16919. For ports that have it socklen_t, SIZE_MAX is
> >> > too large. We can however explicitly cast it to the type of cmsg_len so it
> >> > will fit according to that type.
> >> > ---
> >> > socket/tst-cmsghdr-skeleton.c | 2 +-
> >> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/socket/tst-cmsghdr-skeleton.c b/socket/tst-cmsghdr-skeleton.c
> >> > index 296a0a8581..9516139f87 100644
> >> > --- a/socket/tst-cmsghdr-skeleton.c
> >> > +++ b/socket/tst-cmsghdr-skeleton.c
> >> > @@ -49,7 +49,7 @@ RUN_TEST_FUNCNAME (CMSG_NXTHDR_IMPL) (void)
> >> > /* The first header length is so big, using it would cause an overflow. */
> >> > cmsg = CMSG_FIRSTHDR (&m);
> >> > TEST_VERIFY_EXIT ((char *) cmsg == cmsgbuf);
> >> > - cmsg->cmsg_len = SIZE_MAX;
> >> > + cmsg->cmsg_len = (__typeof (cmsg->cmsg_len)) SIZE_MAX;
> >>
> >> What does that fix?
> >
> > 64bit hurd, where cmsg_len is socklen_t as the standards require (thus
> > 32bit).
>
> And what does it fix?
You mean the error message? The SIZE_MAX constant truncation down from
64bit to 32bit:
x86_64-glibc-gnu-gcc tst-cmsghdr.c -c -std=gnu11 -fgnu89-inline -g -O2 -Wall -Wwrite-strings -Wundef -Werror -fmerge-all-constants -frounding-math -fno-stack-protector -fno-common -Wno-parentheses -Wstrict-prototypes -Wold-style-definition -fmath-errno -fPIE -I../include -I/mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/socket -I/mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc -I../sysdeps/mach/hurd/x86_64 -I../sysdeps/mach/hurd/x86 -I../sysdeps/mach/hurd/x86_64/htl -I../sysdeps/mach/hurd/htl -I../sysdeps/hurd/htl -I../sysdeps/mach/htl -I../sysdeps/htl/include -I../sysdeps/htl -I../sysdeps/pthread -I../sysdeps/mach/hurd/x86/htl -I../sysdeps/x86_64/htl -I../sysdeps/x86/htl -I../sysdeps/mach/hurd -I../sysdeps/gnu -I../sysdeps/unix/bsd -I../sysdeps/unix/inet -I../sysdeps/mach/x86_64 -I../sysdeps/mach/x86 -I../sysdeps/mach/include -I../sysdeps/mach -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../sysdeps/x86_64 -I../sysdeps/x86/include -I../sysdeps/x86 -I../sysdeps/ieee754/float128 -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/hurd/include -I../sysdeps/hurd -I../sysdeps/unix -I../sysdeps/posix -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I../hurd -I/mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/hurd/ -I../mach -I/mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/mach/ -I.. -I../libio -I. -D_LIBC_REENTRANT -include /mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/libc-modules.h -DMODULE_NAME=testsuite -include ../include/libc-symbols.h -DPIC -DTOP_NAMESPACE=glibc -o /mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/socket/tst-cmsghdr.o -MD -MP -MF /mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/socket/tst-cmsghdr.o.dt -MT /mnt/scratch/sthibault/build-glibc/build/glibcs/x86_64-gnu/glibc/socket/tst-cmsghdr.o
In file included from ../include/stdint.h:1,
from tst-cmsghdr-skeleton.c:24,
from tst-cmsghdr.c:31:
tst-cmsghdr-skeleton.c: In function 'run_test_CMSG_NXTHDR':
../stdlib/stdint.h:227:33: error: conversion from 'long unsigned int' to 'socklen_t' {aka 'unsigned int'} changes value from '18446744073709551615' to '4294967295' [-Werror=overflow]
227 | # define SIZE_MAX (18446744073709551615UL)
| ^
tst-cmsghdr-skeleton.c:52:20: note: in expansion of macro 'SIZE_MAX'
52 | cmsg->cmsg_len = SIZE_MAX;
| ^~~~~~~~
Samuel
@@ -49,7 +49,7 @@ RUN_TEST_FUNCNAME (CMSG_NXTHDR_IMPL) (void)
/* The first header length is so big, using it would cause an overflow. */
cmsg = CMSG_FIRSTHDR (&m);
TEST_VERIFY_EXIT ((char *) cmsg == cmsgbuf);
- cmsg->cmsg_len = SIZE_MAX;
+ cmsg->cmsg_len = (__typeof (cmsg->cmsg_len)) SIZE_MAX;
cmsg = CMSG_NXTHDR_IMPL (&m, cmsg);
TEST_VERIFY_EXIT (cmsg == NULL);