commit 0ce6be4a70781fbc3e17c9b6c9732f8144fe6283 Author: Jacob Welsh AuthorDate: Sun Nov 27 04:21:53 2022 +0000 Commit: Jacob Welsh CommitDate: Sun Nov 27 04:34:36 2022 +0000 Type: portability fix imap/test-imap-client-hibernate: use relative rather than absolute paths for temp dir In one setting, the full path ran afoul of the path length limit on unix domain socket addresses (108 characters on Linux), and it only seems to complicate the code anyway. While we're here, stop dot-prefixing the temp dir as there's no good reason to hide it. diff --git a/NEWS b/NEWS index 73814c00dc..dc57bd7d30 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,7 @@ v2.4.0 2022-11-26 Jacob Welsh < http://fixpoint.welshcomputing.com/ > - lib-program-client: Trim test that breaks on no-ipv6 kernels and fix function name (net_connect_ip) in error message. - lib-charset: Drop iconv tests based on UTF-7 source encoding, which isn't implemented in musl and didn't turn up in a search of my own 12 year email collection. - lib: Fix file_cache_errors test on musl by not demanding specific error strings. + - imap/test-imap-client-hibernate: Use relative path for temp dir to bypass path length limit on unix domain socket addresses. - imap-hibernate: Trap possible uninitialized use of pointer on stack (new_tag in imap_client_input_idle_cmd) by zeroing. - lib-imap: imap_bodystructure_parse_full(): Reset parts.data on failure to prevent caller confusion (ported from release-2.3 branch). diff --git a/src/imap/test-imap-client-hibernate.c b/src/imap/test-imap-client-hibernate.c index 6136019a84..8026520f45 100644 --- a/src/imap/test-imap-client-hibernate.c +++ b/src/imap/test-imap-client-hibernate.c @@ -19,7 +19,7 @@ #include -#define TEMP_DIRNAME ".test-imap-client-hibernate" +#define TEMP_DIRNAME "_test-imap-client-hibernate" #define EVILSTR "\t\r\n\001" @@ -33,7 +33,6 @@ struct test_imap_client_hibernate { imap_client_created_func_t *hook_client_created = NULL; bool imap_debug = FALSE; -static const char *tmpdir; static struct mail_storage_service_ctx *storage_service; void imap_refresh_proctitle(void) { } @@ -152,7 +151,7 @@ static void test_imap_client_hibernate(void) const char *const input_userdb[] = { "mailbox_list_index=no", - t_strdup_printf("mail=mbox:%s/mbox", tmpdir), + "mail=mbox:"TEMP_DIRNAME"/mbox", NULL }; struct mail_storage_service_input input = { @@ -165,7 +164,7 @@ static void test_imap_client_hibernate(void) test_assert(net_addr2ip("127.0.0.2", &input.remote_ip) == 0); test_assert(mail_storage_service_lookup_next(storage_service, &input, &service_user, &mail_user, &error) == 1); - mail_user->set->base_dir = tmpdir; + mail_user->set->base_dir = TEMP_DIRNAME; mail_user->set->mail_log_prefix = EVILSTR"%u"; mail_user->session_id = EVILSTR"session"; i_zero(&smtp_set); @@ -191,14 +190,14 @@ static void test_imap_client_hibernate(void) /* imap-hibernate socket doesn't exist */ test_begin("imap client hibernate: socket not found"); - test_expect_error_string("/"TEMP_DIRNAME"/imap-hibernate) failed: No such file or directory"); + test_expect_error_string(TEMP_DIRNAME"/imap-hibernate) failed: No such file or directory"); test_assert(!imap_client_hibernate(&client, &error)); test_expect_no_more_errors(); test_assert(strstr(error, "net_connect_unix") != NULL); test_end(); /* imap-hibernate socket times out */ - const char *socket_path = t_strdup_printf("%s/imap-hibernate", tmpdir); + const char *socket_path = TEMP_DIRNAME"/imap-hibernate"; ctx.fd_listen = net_listen_unix(socket_path, 1); if (ctx.fd_listen == -1) i_fatal("net_listen_unix(%s) failed: %m", socket_path); @@ -245,19 +244,14 @@ static void test_cleanup(void) { const char *error; - if (unlink_directory(tmpdir, UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0) + if (unlink_directory(TEMP_DIRNAME, UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0) i_error("unlink_directory() failed: %s", error); } static void test_init(void) { - const char *cwd, *error; - - test_assert(t_get_working_dir(&cwd, &error) == 0); - tmpdir = t_strconcat(cwd, "/"TEMP_DIRNAME, NULL); - test_cleanup(); - if (mkdir(tmpdir, 0700) < 0) + if (mkdir(TEMP_DIRNAME, 0700) < 0) i_fatal("mkdir() failed: %m"); test_subprocesses_init(FALSE);