5967
5955
char *const filename = strdup("/nonexistent/socket");
5968
5956
__attribute__((cleanup(string_set_clear)))
5969
5957
string_set cancelled_filenames = {};
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,
5958
const size_t oversized = 1024*1024; /* Limit seems to be 212960 */
5959
__attribute__((cleanup(cleanup_buffer)))
5961
.data=malloc(oversized),
5963
.allocated=oversized,
5965
g_assert_nonnull(password.data);
6025
5966
if(mlock(password.data, password.allocated) != 0){
6026
5967
g_assert_true(errno == EPERM or errno == ENOMEM);
5969
/* Construct test password buffer */
5970
/* Start with + since that is what the real procotol uses */
5971
password.data[0] = '+';
5972
/* Set a special character at string end just to mark the end */
5973
password.data[oversized-3] = 'y';
5974
/* Set NUL at buffer end, as suggested by the protocol */
5975
password.data[oversized-2] = '\0';
5976
/* Fill rest of password with 'x' */
5977
memset(password.data+1, 'x', oversized-3);
6029
5979
__attribute__((cleanup(cleanup_queue)))
6030
5980
task_queue *queue = create_queue();
6031
5981
g_assert_nonnull(queue);
6032
5983
g_assert_cmpint(socketpair(PF_LOCAL, SOCK_DGRAM
6033
5984
| SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
6034
5985
socketfds), ==, 0);