5968
5967
char *const filename = strdup("/nonexistent/socket");
5969
5968
__attribute__((cleanup(string_set_clear)))
5970
5969
string_set cancelled_filenames = {};
5971
const size_t oversized = 1024*1024; /* Limit seems to be 212960 */
5972
__attribute__((cleanup(cleanup_buffer)))
5974
.data=malloc(oversized),
5976
.allocated=oversized,
5972
/* Find a message size which triggers EMSGSIZE */
5973
__attribute__((cleanup(cleanup_string)))
5974
char *message_buffer = NULL;
5975
size_t message_size = PIPE_BUF + 1;
5976
for(ssize_t ssret = 0; ssret >= 0; message_size += 1024){
5977
if(message_size >= 1024*1024*1024){ /* 1 GiB */
5978
g_test_skip("Skipping EMSGSIZE test: Will not try 1GiB");
5981
free(message_buffer);
5982
message_buffer = malloc(message_size);
5983
if(message_buffer == NULL){
5984
g_test_skip("Skipping EMSGSIZE test");
5985
g_test_message("Failed to malloc() %" PRIuMAX " bytes",
5986
(uintmax_t)message_size);
5989
/* Fill buffer with 'x' */
5990
memset(message_buffer, 'x', message_size);
5991
/* Create a new socketpair for each message size to avoid having
5992
to empty the pipe by reading the message to a separate buffer
5994
g_assert_cmpint(socketpair(PF_LOCAL, SOCK_DGRAM
5995
| SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
5997
ssret = send(socketfds[1], message_buffer, message_size,
5999
error_t saved_errno = errno;
6000
g_assert_cmpint(close(socketfds[0]), ==, 0);
6001
g_assert_cmpint(close(socketfds[1]), ==, 0);
6004
if(saved_errno != EMSGSIZE) {
6005
g_test_skip("Skipping EMSGSIZE test");
6006
g_test_message("Error on send(): %s", strerror(saved_errno));
6009
} else if(ssret != (ssize_t)message_size){
6010
g_test_skip("Skipping EMSGSIZE test");
6011
g_test_message("Partial send(): %" PRIuMAX " of %" PRIdMAX
6012
" bytes", (uintmax_t)ssret,
6013
(intmax_t)message_size);
6017
g_test_message("EMSGSIZE triggered by %" PRIdMAX " bytes",
6018
(intmax_t)message_size);
6021
.data=message_buffer,
6022
.length=message_size - 2, /* Compensate for added '+' and NUL */
6023
.allocated=message_size,
5978
g_assert_nonnull(password.data);
5979
6025
if(mlock(password.data, password.allocated) != 0){
5980
6026
g_assert_true(errno == EPERM or errno == ENOMEM);
5982
/* Construct test password buffer */
5983
/* Start with + since that is what the real protocol uses */
5984
password.data[0] = '+';
5985
/* Set a special character at string end just to mark the end */
5986
password.data[oversized-3] = 'y';
5987
/* Set NUL at buffer end, as suggested by the protocol */
5988
password.data[oversized-2] = '\0';
5989
/* Fill rest of password with 'x' */
5990
memset(password.data+1, 'x', oversized-3);
5992
6029
__attribute__((cleanup(cleanup_queue)))
5993
6030
task_queue *queue = create_queue();
5994
6031
g_assert_nonnull(queue);
5996
6032
g_assert_cmpint(socketpair(PF_LOCAL, SOCK_DGRAM
5997
6033
| SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
5998
6034
socketfds), ==, 0);