From c147881d999fa966ea266d6feac2a3fabeef511b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 23 Jun 2024 08:41:36 -0400 Subject: Skip socket file type test with absurdly long TMPDIR If TMPDIR is so long that it doesn't fit in the socket address field, then it's impossible to create a socket in the temporary directory. This is a pretty weird situation that would never happen on a normal system, so I think the test can just be skipped without the reduced coverage being a problem. --- test/test_filesystem.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'test/test_filesystem.c') diff --git a/test/test_filesystem.c b/test/test_filesystem.c index 4a1ad4f..87a3d15 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -162,14 +162,18 @@ test_file_type(void) const socklen_t addr_len = sizeof(struct sockaddr_un); struct sockaddr_un* const addr = (struct sockaddr_un*)calloc(1, addr_len); - addr->sun_family = AF_UNIX; - strncpy(addr->sun_path, file_path, sizeof(addr->sun_path) - 1); - - const int fd = bind(sock, (struct sockaddr*)addr, addr_len); - if (fd >= 0) { - assert(zix_file_type(file_path) == ZIX_FILE_TYPE_SOCKET); - assert(!zix_remove(file_path)); - close(fd); + if (strlen(file_path) < sizeof(addr->sun_path)) { + addr->sun_family = AF_UNIX; + strncpy(addr->sun_path, file_path, sizeof(addr->sun_path) - 1); + + const int fd = bind(sock, (struct sockaddr*)addr, addr_len); + if (fd >= 0) { + assert(zix_file_type(file_path) == ZIX_FILE_TYPE_SOCKET); + assert(!zix_remove(file_path)); + close(fd); + } + } else { + fprintf(stderr, "warning: Skipped socket test with oddly long TMPDIR\n"); } close(sock); -- cgit v1.2.1