On Sun, Dec 29, 2024 at 11:33:47PM +0100, Samuel Thibault wrote:
>
> See the error test, it's about G_CREDENTIALS_NATIVE_SIZE, see its
> definition:
>
> #define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct cmsgcred))
>
> And the definition of struct cmsgcred in bits/socket.h
>
I wrote a little test-case (attached) that compares several sizes of the objects
involved in the GBus authentication.
Here are the results for `hurd-amd64`:
$ cc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-gnu/glib-2.0/include \
-pthread cred_size.c -lgio-2.0 -lgobject-2.0 -lglib-2.0 \
-o cred_size
$ ./cred_size
sizeof (int): 4
sizeof(struct cmsgcred): 84
CMSG_LEN(sizeof (int)): 20
CMSG_LEN(g_socket_control_message_get_size (scm)): 100
and here the results for `hurd-i386`:
$ ./cred_size
sizeof (int): 4
sizeof(struct cmsgcred): 84
CMSG_LEN(sizeof (int)): 16
CMSG_LEN(g_socket_control_message_get_size (scm)): 96
So, it seems CMSG_LEN generates sizes that are off by 4 bytes.
I'll check the macro next, to see if I can pinpoint that extra 4 bytes.
Thanks
#include <gio/gio.h>
#include <stdio.h>
#include <sys/socket.h>
int
main(int argc, char **argv)
{
size_t int_size = sizeof (int);
printf("sizeof (int): %lu\n", int_size);
size_t cred_size = sizeof(struct cmsgcred);
printf("sizeof(struct cmsgcred): %lu\n", cred_size);
size_t cmsg_len = CMSG_LEN(sizeof (int));
printf("CMSG_LEN(sizeof (int)): %lu\n", cmsg_len);
GCredentials *creds = g_credentials_new();
GSocketControlMessage *scm = g_unix_credentials_message_new_with_credentials(creds);
size_t cms = CMSG_LEN(g_socket_control_message_get_size (scm));
printf("CMSG_LEN(g_socket_control_message_get_size (scm)): %lu\n", cms);
return 0;
}
/* vim: set sw=2 ts=2 et: */