5967
5968
char *const filename = strdup("/nonexistent/socket");
5968
5969
__attribute__((cleanup(string_set_clear)))
5969
5970
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
message_buffer = realloc(message_buffer, message_size);
5982
if(message_buffer == NULL){
5983
g_test_skip("Skipping EMSGSIZE test");
5984
g_test_message("Failed to malloc() %" PRIuMAX " bytes",
5985
(uintmax_t)message_size);
5988
/* Fill buffer with 'x' */
5989
memset(message_buffer, 'x', message_size);
5990
/* Create a new socketpair for each message size to avoid having
5991
to empty the pipe by reading the message to a separate buffer
5993
g_assert_cmpint(socketpair(PF_LOCAL, SOCK_DGRAM
5994
| SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
5996
ssret = send(socketfds[1], message_buffer, message_size,
5998
error_t saved_errno = errno;
5999
g_assert_cmpint(close(socketfds[0]), ==, 0);
6000
g_assert_cmpint(close(socketfds[1]), ==, 0);
6003
if(saved_errno != EMSGSIZE) {
6004
g_test_skip("Skipping EMSGSIZE test");
6005
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,
5971
const size_t oversized = 1024*1024; /* Limit seems to be 212960 */
5972
__attribute__((cleanup(cleanup_buffer)))
5974
.data=malloc(oversized),
5976
.allocated=oversized,
5978
g_assert_nonnull(password.data);
6025
5979
if(mlock(password.data, password.allocated) != 0){
6026
5980
g_assert_true(errno == EPERM or errno == ENOMEM);
5982
/* Construct test password buffer */
5983
/* Start with + since that is what the real procotol 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);
6029
5992
__attribute__((cleanup(cleanup_queue)))
6030
5993
task_queue *queue = create_queue();
6031
5994
g_assert_nonnull(queue);
6032
5996
g_assert_cmpint(socketpair(PF_LOCAL, SOCK_DGRAM
6033
5997
| SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
6034
5998
socketfds), ==, 0);