From: Martti Rannanjärvi Date: Tue, 17 May 2016 07:35:35 +0000 (+0300) Subject: Remove t_malloc in favour of t_malloc_no0 X-Git-Tag: 2.3.0.rc1~3620 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0175d37a5ae5a4d146ca41b684bd38d9b03683cb;p=thirdparty%2Fdovecot%2Fcore.git Remove t_malloc in favour of t_malloc_no0 Using either t_malloc_no0 or t_malloc0 makes it clear whether the allocated memory is zeroed or not. --- diff --git a/src/auth/auth-request-var-expand.c b/src/auth/auth-request-var-expand.c index f1f041e473..3b0013601e 100644 --- a/src/auth/auth-request-var-expand.c +++ b/src/auth/auth-request-var-expand.c @@ -78,7 +78,7 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request, /* keep the extra fields at the beginning. the last static_tab field contains the ending NULL-fields. */ - tab = ret_tab = t_malloc((*count + auth_count) * sizeof(*tab)); + tab = ret_tab = t_malloc_no0((*count + auth_count) * sizeof(*tab)); memset(tab, 0, *count * sizeof(*tab)); tab += *count; *count += auth_count; diff --git a/src/auth/password-scheme.c b/src/auth/password-scheme.c index 1633e50b1e..bdff0f1142 100644 --- a/src/auth/password-scheme.c +++ b/src/auth/password-scheme.c @@ -262,7 +262,7 @@ const char *password_generate_salt(size_t len) unsigned int i; char *salt; - salt = t_malloc(len + 1); + salt = t_malloc_no0(len + 1); random_fill(salt, len); for (i = 0; i < len; i++) salt[i] = salt_chars[salt[i] % (sizeof(salt_chars)-1)]; @@ -400,7 +400,7 @@ sha1_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(SHA1_RESULTLEN); + digest = t_malloc_no0(SHA1_RESULTLEN); sha1_get_digest(plaintext, strlen(plaintext), digest); *raw_password_r = digest; @@ -413,7 +413,7 @@ sha256_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(SHA256_RESULTLEN); + digest = t_malloc_no0(SHA256_RESULTLEN); sha256_get_digest(plaintext, strlen(plaintext), digest); *raw_password_r = digest; @@ -426,7 +426,7 @@ sha512_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(SHA512_RESULTLEN); + digest = t_malloc_no0(SHA512_RESULTLEN); sha512_get_digest(plaintext, strlen(plaintext), digest); *raw_password_r = digest; @@ -441,7 +441,7 @@ ssha_generate(const char *plaintext, const char *user ATTR_UNUSED, unsigned char *digest, *salt; struct sha1_ctxt ctx; - digest = t_malloc(SHA1_RESULTLEN + SSHA_SALT_LEN); + digest = t_malloc_no0(SHA1_RESULTLEN + SSHA_SALT_LEN); salt = digest + SHA1_RESULTLEN; random_fill(salt, SSHA_SALT_LEN); @@ -482,7 +482,7 @@ ssha256_generate(const char *plaintext, const char *user ATTR_UNUSED, unsigned char *digest, *salt; struct sha256_ctx ctx; - digest = t_malloc(SHA256_RESULTLEN + SSHA256_SALT_LEN); + digest = t_malloc_no0(SHA256_RESULTLEN + SSHA256_SALT_LEN); salt = digest + SHA256_RESULTLEN; random_fill(salt, SSHA256_SALT_LEN); @@ -525,7 +525,7 @@ ssha512_generate(const char *plaintext, const char *user ATTR_UNUSED, unsigned char *digest, *salt; struct sha512_ctx ctx; - digest = t_malloc(SHA512_RESULTLEN + SSHA512_SALT_LEN); + digest = t_malloc_no0(SHA512_RESULTLEN + SSHA512_SALT_LEN); salt = digest + SHA512_RESULTLEN; random_fill(salt, SSHA512_SALT_LEN); @@ -568,7 +568,7 @@ smd5_generate(const char *plaintext, const char *user ATTR_UNUSED, unsigned char *digest, *salt; struct md5_context ctx; - digest = t_malloc(MD5_RESULTLEN + SMD5_SALT_LEN); + digest = t_malloc_no0(MD5_RESULTLEN + SMD5_SALT_LEN); salt = digest + MD5_RESULTLEN; random_fill(salt, SMD5_SALT_LEN); @@ -646,7 +646,7 @@ cram_md5_generate(const char *plaintext, const char *user ATTR_UNUSED, struct hmac_context ctx; unsigned char *context_digest; - context_digest = t_malloc(CRAM_MD5_CONTEXTLEN); + context_digest = t_malloc_no0(CRAM_MD5_CONTEXTLEN); hmac_init(&ctx, (const unsigned char *)plaintext, strlen(plaintext), &hash_method_md5); hmac_md5_get_cram_context(&ctx, context_digest); @@ -677,7 +677,7 @@ digest_md5_generate(const char *plaintext, const char *user, } /* user:realm:passwd */ - digest = t_malloc(MD5_RESULTLEN); + digest = t_malloc_no0(MD5_RESULTLEN); str = t_strdup_printf("%s:%s:%s", user, realm, plaintext); md5_get_digest(str, strlen(str), digest); @@ -691,7 +691,7 @@ plain_md4_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(MD4_RESULTLEN); + digest = t_malloc_no0(MD4_RESULTLEN); md4_get_digest(plaintext, strlen(plaintext), digest); *raw_password_r = digest; @@ -704,7 +704,7 @@ plain_md5_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(MD5_RESULTLEN); + digest = t_malloc_no0(MD5_RESULTLEN); md5_get_digest(plaintext, strlen(plaintext), digest); *raw_password_r = digest; @@ -717,7 +717,7 @@ lm_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(LM_HASH_SIZE); + digest = t_malloc_no0(LM_HASH_SIZE); lm_hash(plaintext, digest); *raw_password_r = digest; @@ -730,7 +730,7 @@ ntlm_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(NTLMSSP_HASH_SIZE); + digest = t_malloc_no0(NTLMSSP_HASH_SIZE); ntlm_v1_hash(plaintext, digest); *raw_password_r = digest; @@ -782,7 +782,7 @@ rpa_generate(const char *plaintext, const char *user ATTR_UNUSED, { unsigned char *digest; - digest = t_malloc(MD5_RESULTLEN); + digest = t_malloc_no0(MD5_RESULTLEN); password_generate_rpa(plaintext, digest); *raw_password_r = digest; diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index 92dba0d839..a3e34635b2 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -226,7 +226,7 @@ get_ssh_cmd_args(const char *host, const char *login, const char *mail_user) string_t *str, *str2; const char *value, *const *args; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = mail_user; diff --git a/src/doveadm/doveadm-dump-log.c b/src/doveadm/doveadm-dump-log.c index bbcf35b966..9b7e43cbb5 100644 --- a/src/doveadm/doveadm-dump-log.c +++ b/src/doveadm/doveadm-dump-log.c @@ -520,7 +520,7 @@ static int dump_record(int fd, uint64_t *modseq) if (hdr.size < sizeof(hdr)) { i_fatal("Invalid header size %u", hdr.size); } else if (hdr.size < 1024*1024) { - unsigned char *buf = t_malloc(hdr.size); + unsigned char *buf = t_malloc_no0(hdr.size); ret = read(fd, buf, hdr.size - sizeof(hdr)); if (ret != (ssize_t)(hdr.size - sizeof(hdr))) { diff --git a/src/imap-hibernate/imap-client.c b/src/imap-hibernate/imap-client.c index 4521d0ad68..c89c0ab3b7 100644 --- a/src/imap-hibernate/imap-client.c +++ b/src/imap-hibernate/imap-client.c @@ -356,7 +356,7 @@ imap_client_get_var_expand_table(struct imap_client *client) struct var_expand_table *tab; const char *auth_user; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = client->state.username; diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 0bbd1d55f2..3fdaff773d 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -247,7 +247,7 @@ const char *client_stats(struct client *client) struct var_expand_table *tab; string_t *str; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = dec2str(i_stream_get_absolute_offset(client->input)); diff --git a/src/lib-http/http-transfer-chunked.c b/src/lib-http/http-transfer-chunked.c index 4d3bd625be..fff71cf931 100644 --- a/src/lib-http/http-transfer-chunked.c +++ b/src/lib-http/http-transfer-chunked.c @@ -623,7 +623,7 @@ http_transfer_chunked_ostream_sendv(struct ostream_private *stream, /* create new iovec */ prefix = t_strdup_printf("%llx\r\n", (unsigned long long)tcstream->chunk_size); iov_count = iov_count_new + 2; - iov_new = t_malloc(sizeof(struct const_iovec) * iov_count); + iov_new = t_malloc_no0(sizeof(struct const_iovec) * iov_count); iov_new[0].iov_base = prefix; iov_new[0].iov_len = strlen(prefix); memcpy(&iov_new[1], iov, sizeof(struct const_iovec) * iov_count_new); diff --git a/src/lib-imap/imap-date.c b/src/lib-imap/imap-date.c index 8c86a74405..0be4fd23f9 100644 --- a/src/lib-imap/imap-date.c +++ b/src/lib-imap/imap-date.c @@ -183,7 +183,7 @@ imap_to_datetime_tm(const struct tm *tm, int timezone_offset) char *buf; /* @UNSAFE: but faster than t_strdup_printf() call.. */ - buf = t_malloc(27); + buf = t_malloc_no0(27); imap_to_date_tm(buf, tm); buf[11] = ' '; diff --git a/src/lib-imap/imap-utf7.c b/src/lib-imap/imap-utf7.c index db530d7672..87ea8194d8 100644 --- a/src/lib-imap/imap-utf7.c +++ b/src/lib-imap/imap-utf7.c @@ -82,7 +82,7 @@ int imap_utf8_to_utf7(const char *src, string_t *dest) /* at least one encoded character */ str_append_n(dest, src, p-src); - utf16 = t_malloc(strlen(p)*2); + utf16 = t_malloc_no0(strlen(p)*2); while (*p != '\0') { if (*p == '&') { str_append(dest, "&-"); diff --git a/src/lib-index/test-mail-index-sync-ext.c b/src/lib-index/test-mail-index-sync-ext.c index 7a9f29d152..34c7b6d0b2 100644 --- a/src/lib-index/test-mail-index-sync-ext.c +++ b/src/lib-index/test-mail-index-sync-ext.c @@ -48,7 +48,7 @@ static void test_mail_index_sync_ext_atomic_inc(void) ctx.view->map->hdr.record_size = sizeof(struct mail_index_record) + 16; ctx.view->map->rec_map = t_new(struct mail_index_record_map, 1); ctx.view->map->rec_map->records = - t_malloc(ctx.view->map->hdr.record_size); + t_malloc_no0(ctx.view->map->hdr.record_size); t_array_init(&ctx.view->map->extensions, 4); ext = array_append_space(&ctx.view->map->extensions); ext->record_offset = sizeof(struct mail_index_record); diff --git a/src/lib-lda/mail-deliver.c b/src/lib-lda/mail-deliver.c index 035a2fa4e8..8ee055b707 100644 --- a/src/lib-lda/mail-deliver.c +++ b/src/lib-lda/mail-deliver.c @@ -74,7 +74,7 @@ mail_deliver_get_log_var_expand_table_full(struct mail_deliver_context *ctx, const char *str; uoff_t size; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = message; diff --git a/src/lib-lda/mail-send.c b/src/lib-lda/mail-send.c index 359d9e9c2b..bf2d404caa 100644 --- a/src/lib-lda/mail-send.c +++ b/src/lib-lda/mail-send.c @@ -34,7 +34,7 @@ get_var_expand_table(struct mail *mail, const char *reason, struct var_expand_table *tab; const char *subject; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = "\r\n"; diff --git a/src/lib-mail/mail-user-hash.c b/src/lib-mail/mail-user-hash.c index c29aca0e8a..60b3a8f09b 100644 --- a/src/lib-mail/mail-user-hash.c +++ b/src/lib-mail/mail-user-hash.c @@ -30,7 +30,7 @@ unsigned int mail_user_hash(const char *username, const char *format) } else T_BEGIN { string_t *str = t_str_new(128); - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = username; tab[1].value = t_strcut(username, '@'); diff --git a/src/lib-ssl-iostream/iostream-openssl-common.c b/src/lib-ssl-iostream/iostream-openssl-common.c index 439ccfd08c..52e38c5c69 100644 --- a/src/lib-ssl-iostream/iostream-openssl-common.c +++ b/src/lib-ssl-iostream/iostream-openssl-common.c @@ -174,7 +174,7 @@ static const char *ssl_err2str(unsigned long err, const char *data, int flags) char *buf; size_t err_size = 256; - buf = t_malloc(err_size); + buf = t_malloc_no0(err_size); buf[err_size-1] = '\0'; ERR_error_string_n(err, buf, err_size-1); ret = buf; diff --git a/src/lib-ssl-iostream/iostream-openssl.c b/src/lib-ssl-iostream/iostream-openssl.c index 0f937b3cc9..daccb298bc 100644 --- a/src/lib-ssl-iostream/iostream-openssl.c +++ b/src/lib-ssl-iostream/iostream-openssl.c @@ -664,7 +664,7 @@ openssl_iostream_get_peer_name(struct ssl_iostream *ssl_io) if (len < 0) name = ""; else { - name = t_malloc(len + 1); + name = t_malloc_no0(len + 1); if (X509_NAME_get_text_by_NID(X509_get_subject_name(x509), ssl_io->username_nid, name, len + 1) < 0) diff --git a/src/lib-storage/index/shared/shared-storage.c b/src/lib-storage/index/shared/shared-storage.c index 8a4770325f..c9717728b1 100644 --- a/src/lib-storage/index/shared/shared-storage.c +++ b/src/lib-storage/index/shared/shared-storage.c @@ -235,7 +235,7 @@ int shared_storage_get_namespace(struct mail_namespace **_ns, /* expand the namespace prefix and see if it already exists. this should normally happen only when the mailbox is being opened */ - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = userdomain; tab[1].value = username; diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index 1928a3d579..b7dae9eb41 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -412,7 +412,7 @@ get_var_expand_table(struct master_service *service, }; struct var_expand_table *tab; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = input->username; diff --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index 72dc53087a..38fa559db7 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -739,7 +739,7 @@ const char *mailbox_list_default_get_vname(struct mailbox_list *list, if (list_sep != ns_sep || prefix_len > 0) { /* @UNSAFE */ name_len = strlen(vname); - ret = t_malloc(prefix_len + name_len + 1); + ret = t_malloc_no0(prefix_len + name_len + 1); memcpy(ret, list->ns->prefix, prefix_len); for (i = 0; i < name_len; i++) { ret[i + prefix_len] = diff --git a/src/lib/data-stack.c b/src/lib/data-stack.c index 4802110f5b..c9ee52dea6 100644 --- a/src/lib/data-stack.c +++ b/src/lib/data-stack.c @@ -435,7 +435,7 @@ static void *t_malloc_real(size_t size, bool permanent) return ret; } -void *t_malloc(size_t size) +void *t_malloc_no0(size_t size) { return t_malloc_real(size, TRUE); } diff --git a/src/lib/data-stack.h b/src/lib/data-stack.h index 142981dab3..eb5546f3cb 100644 --- a/src/lib/data-stack.h +++ b/src/lib/data-stack.h @@ -75,7 +75,7 @@ void t_pop_check(unsigned int *id) ATTR_HOT; t_malloc() calls never fail. If there's not enough memory left, i_panic() will be called. */ -void *t_malloc(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL; +void *t_malloc_no0(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL; void *t_malloc0(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL; /* Try growing allocated memory. Returns TRUE if successful. Works only diff --git a/src/lib/hex-binary.c b/src/lib/hex-binary.c index 0fb89ef167..16f7868ec7 100644 --- a/src/lib/hex-binary.c +++ b/src/lib/hex-binary.c @@ -28,7 +28,7 @@ binary_to_hex_case(unsigned char *dest, const unsigned char *data, const char *binary_to_hex(const unsigned char *data, size_t size) { - unsigned char *dest = t_malloc(size * 2 + 1); + unsigned char *dest = t_malloc_no0(size * 2 + 1); binary_to_hex_case(dest, data, size, FALSE); dest[size*2] = '\0'; @@ -37,7 +37,7 @@ const char *binary_to_hex(const unsigned char *data, size_t size) const char *binary_to_hex_ucase(const unsigned char *data, size_t size) { - unsigned char *dest = t_malloc(size * 2 + 1); + unsigned char *dest = t_malloc_no0(size * 2 + 1); binary_to_hex_case(dest, data, size, TRUE); dest[size*2] = '\0'; diff --git a/src/lib/mempool-datastack.c b/src/lib/mempool-datastack.c index 2e119190c2..0a986af2f1 100644 --- a/src/lib/mempool-datastack.c +++ b/src/lib/mempool-datastack.c @@ -123,7 +123,7 @@ static void *pool_data_stack_realloc(pool_t pool, void *mem, return mem; if (!t_try_realloc(mem, new_size)) { - new_mem = t_malloc(new_size); + new_mem = t_malloc_no0(new_size); memcpy(new_mem, mem, old_size); mem = new_mem; } diff --git a/src/lib/mempool-unsafe-datastack.c b/src/lib/mempool-unsafe-datastack.c index a8e7e20c9b..0e3ee65a8d 100644 --- a/src/lib/mempool-unsafe-datastack.c +++ b/src/lib/mempool-unsafe-datastack.c @@ -82,7 +82,7 @@ static void *pool_unsafe_data_stack_realloc(pool_t pool ATTR_UNUSED, return mem; if (!t_try_realloc(mem, new_size)) { - new_mem = t_malloc(new_size); + new_mem = t_malloc_no0(new_size); memcpy(new_mem, mem, old_size); mem = new_mem; } diff --git a/src/lib/net.c b/src/lib/net.c index 6206e65448..5cfc91b2d5 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -651,7 +651,7 @@ int net_gethostbyname(const char *addr, struct ip_addr **ips, count++; *ips_count = count; - *ips = t_malloc(sizeof(struct ip_addr) * count); + *ips = t_malloc_no0(sizeof(struct ip_addr) * count); count = 0; for (ai = origai; ai != NULL; ai = ai->ai_next, count++) { diff --git a/src/lib/strfuncs.c b/src/lib/strfuncs.c index db877141a5..d8d3bc4fc4 100644 --- a/src/lib/strfuncs.c +++ b/src/lib/strfuncs.c @@ -313,7 +313,7 @@ const char *t_str_replace(const char *str, char from, char to) return str; len = strlen(str); - out = t_malloc(len + 1); + out = t_malloc_no0(len + 1); for (i = 0; i < len; i++) { if (str[i] == from) out[i] = to; @@ -758,7 +758,7 @@ const char *dec2str(uintmax_t number) int pos; pos = MAX_INT_STRLEN; - buffer = t_malloc(pos); + buffer = t_malloc_no0(pos); buffer[--pos] = '\0'; do { diff --git a/src/lib/test-data-stack.c b/src/lib/test-data-stack.c index 055ac3d57a..c870249f6b 100644 --- a/src/lib/test-data-stack.c +++ b/src/lib/test-data-stack.c @@ -11,7 +11,7 @@ static void test_ds_buffers(void) unsigned char *p; size_t left = t_get_bytes_available(); while (left < 10000) { - t_malloc(left); /* force a new block */ + t_malloc_no0(left); /* force a new block */ left = t_get_bytes_available(); } left -= 64; /* make room for the sentry if DEBUG */ @@ -33,7 +33,7 @@ static void test_ds_buffers(void) test_begin("data-stack buffer interruption"); T_BEGIN { void *b = t_buffer_get(1000); - void *a = t_malloc(1); + void *a = t_malloc_no0(1); void *b2 = t_buffer_get(1001); test_assert(a == b); /* expected, not guaranteed */ test_assert(b2 != b); @@ -47,7 +47,7 @@ static void test_ds_buffers(void) for (i = 1; i < bigleft-64; i += rand()%32) T_BEGIN { unsigned char *p, *p2; size_t left; - t_malloc(i); + t_malloc_no0(i); left = t_get_bytes_available(); /* The most useful idx for the assert is 'left' */ test_assert_idx(left <= bigleft-i, left); @@ -70,11 +70,11 @@ static void test_ds_realloc() unsigned char *p; size_t left = t_get_bytes_available(); while (left < 10000) { - t_malloc(left); /* force a new block */ + t_malloc_no0(left); /* force a new block */ left = t_get_bytes_available(); } left -= 64; /* make room for the sentry if DEBUG */ - p = t_malloc(1); + p = t_malloc_no0(1); p[0] = 1; for (i = 2; i <= left; i++) { /* grow it */ @@ -99,12 +99,12 @@ static void test_ds_recurse(int depth, int number, size_t size) t_buffer_alloc_type(char *, number); for (i = 0; i < number; i++) { - ps[i] = t_malloc(size/2); + ps[i] = t_malloc_no0(size/2); bool re = t_try_realloc(ps[i], size); i_assert(ps[i] != NULL); if (!re) { try_fails++; - ps[i] = t_malloc(size); + ps[i] = t_malloc_no0(size); } /* drop our own canaries */ memset(ps[i], tag[0], size); @@ -177,8 +177,8 @@ enum fatal_test_state fatal_data_stack(int stage) test_begin("fatal data-stack underrun"); t_id = t_push_named("fatal_data_stack underrun"); size_t left = t_get_bytes_available(); - p = t_malloc(left-80); /* will fit */ - p = t_malloc(100); /* won't fit, will get new block */ + p = t_malloc_no0(left-80); /* will fit */ + p = t_malloc_no0(100); /* won't fit, will get new block */ int seek = 0; /* Seek back for the canary, don't assume endianness */ while(seek > -60 && @@ -191,15 +191,15 @@ enum fatal_test_state fatal_data_stack(int stage) undo_ptr = p + seek; undo_data = *undo_ptr; *undo_ptr = '*'; - /* t_malloc will panic block header corruption */ - (void)t_malloc(10); + /* t_malloc_no0 will panic block header corruption */ + (void)t_malloc_no0(10); return FATAL_TEST_FAILURE; } case 1: case 2: { - test_begin(stage == 1 ? "fatal t_malloc overrun near" : "fatal t_malloc overrun far"); - t_id = t_push_named(stage == 1 ? "fatal t_malloc overrun first" : "fatal t_malloc overrun far"); - unsigned char *p = t_malloc(10); + test_begin(stage == 1 ? "fatal t_malloc_no0 overrun near" : "fatal t_malloc_no0 overrun far"); + t_id = t_push_named(stage == 1 ? "fatal t_malloc_no0 overrun first" : "fatal t_malloc_no0 overrun far"); + unsigned char *p = t_malloc_no0(10); undo_ptr = p + 10 + (stage == 1 ? 0 : 8*4-1); /* presumes sentry size */ undo_data = *undo_ptr; *undo_ptr = '*'; diff --git a/src/lib/test-istream-concat.c b/src/lib/test-istream-concat.c index e61b886886..059aed4c01 100644 --- a/src/lib/test-istream-concat.c +++ b/src/lib/test-istream-concat.c @@ -67,7 +67,7 @@ static bool test_istream_concat_random(void) streams = t_new(struct istream *, stream_count + 1); for (i = 0, offset = 0; i < stream_count; i++) { data_len = rand() % TEST_MAX_ISTREAM_SIZE + 1; - w_data = t_malloc(data_len); + w_data = t_malloc_no0(data_len); for (j = 0; j < data_len; j++) w_data[j] = offset++; streams[i] = test_istream_create_data(w_data, data_len); diff --git a/src/lib/test-istream-seekable.c b/src/lib/test-istream-seekable.c index 08cc95d8ca..e7fdb9407b 100644 --- a/src/lib/test-istream-seekable.c +++ b/src/lib/test-istream-seekable.c @@ -77,7 +77,7 @@ static void test_istream_seekable_random(void) streams = t_new(struct istream *, stream_count + 1); for (i = 0, offset = 0; i < stream_count; i++) { data_len = rand() % 100 + 1; - w_data = t_malloc(data_len); + w_data = t_malloc_no0(data_len); for (j = 0; j < data_len; j++) w_data[j] = offset++; streams[i] = test_istream_create_data(w_data, data_len); diff --git a/src/lib/var-expand.c b/src/lib/var-expand.c index 5d06cebee0..d334c8ed57 100644 --- a/src/lib/var-expand.c +++ b/src/lib/var-expand.c @@ -61,7 +61,7 @@ m_str_reverse(const char *str, struct var_expand_context *ctx ATTR_UNUSED) size_t len = strlen(str); char *p, *rev; - rev = t_malloc(len + 1); + rev = t_malloc_no0(len + 1); rev[len] = '\0'; for (p = rev + len - 1; *str != '\0'; str++) diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 50307d7270..4fde20edfc 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -531,7 +531,7 @@ get_var_expand_table(struct client *client) { struct var_expand_table *tab; - tab = t_malloc(sizeof(login_var_expand_empty_tab)); + tab = t_malloc_no0(sizeof(login_var_expand_empty_tab)); memcpy(tab, login_var_expand_empty_tab, sizeof(login_var_expand_empty_tab)); @@ -641,7 +641,7 @@ client_get_log_str(struct client *client, const char *msg) var_expand_table = get_var_expand_table(client); - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); str = t_str_new(256); diff --git a/src/login-common/login-settings.c b/src/login-common/login-settings.c index f8945f1694..05be020c55 100644 --- a/src/login-common/login-settings.c +++ b/src/login-common/login-settings.c @@ -124,7 +124,7 @@ login_set_var_expand_table(const struct master_service_settings_input *input) }; struct var_expand_table *tab; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = net_ip2addr(&input->local_ip); diff --git a/src/login-common/ssl-proxy-openssl.c b/src/login-common/ssl-proxy-openssl.c index 8bdb68b9aa..be2bcdc6a5 100644 --- a/src/login-common/ssl-proxy-openssl.c +++ b/src/login-common/ssl-proxy-openssl.c @@ -701,7 +701,7 @@ const char *ssl_proxy_get_peer_name(struct ssl_proxy *proxy) if (len < 0) name = ""; else { - name = t_malloc(len + 1); + name = t_malloc_no0(len + 1); if (X509_NAME_get_text_by_NID(X509_get_subject_name(x509), ssl_username_nid, name, len + 1) < 0) name = ""; diff --git a/src/plugins/acl/acl-shared-storage.c b/src/plugins/acl/acl-shared-storage.c index 718573a664..e36af1602e 100644 --- a/src/plugins/acl/acl-shared-storage.c +++ b/src/plugins/acl/acl-shared-storage.c @@ -55,7 +55,7 @@ acl_shared_namespace_add(struct mail_namespace *ns, p = strchr(userdomain, '@'); - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = userdomain; tab[1].value = p == NULL ? userdomain : t_strdup_until(userdomain, p); diff --git a/src/plugins/fts-squat/squat-trie.c b/src/plugins/fts-squat/squat-trie.c index b3d8fa301b..bbf6e89121 100644 --- a/src/plugins/fts-squat/squat-trie.c +++ b/src/plugins/fts-squat/squat-trie.c @@ -658,7 +658,7 @@ node_split_string(struct squat_trie_build_context *ctx, struct squat_node *node) /* make a copy of the leaf string and convert to normal node by removing it. */ - str = t_malloc(leafstr_len); + str = t_malloc_no0(leafstr_len); if (!NODE_IS_DYNAMIC_LEAF(node)) memcpy(str, node->children.static_leaf_string, leafstr_len); else { @@ -892,7 +892,7 @@ squat_data_normalize(struct squat_trie *trie, const unsigned char *data, unsigned char *dest; unsigned int i; - dest = t_malloc(size); + dest = t_malloc_no0(size); for (i = 0; i < size; i++) { if (data[i] == replacement_utf8[0] && i + 2 < size && data[i+1] == replacement_utf8[1] && @@ -922,7 +922,7 @@ squat_trie_build_more_real(struct squat_trie_build_context *ctx, uid = uid * 2 + (type == SQUAT_INDEX_TYPE_HEADER ? 1 : 0); - char_lengths = t_malloc(size); + char_lengths = t_malloc_no0(size); data = squat_data_normalize(trie, input, size); for (i = 0; i < size; i++) { char_lengths[i] = uni_utf8_char_bytes(input[i]); diff --git a/src/plugins/fts-squat/squat-uidlist.c b/src/plugins/fts-squat/squat-uidlist.c index 1b7fb1cad1..348dd646d7 100644 --- a/src/plugins/fts-squat/squat-uidlist.c +++ b/src/plugins/fts-squat/squat-uidlist.c @@ -126,7 +126,7 @@ uidlist_write_array(struct ostream *output, const uint32_t *uid_list, base_uid = uid_list[0] & ~UID_LIST_MASK_RANGE; datastack = uid_count < 1024*8/SQUAT_PACK_MAX_SIZE; if (datastack) - uidbuf = t_malloc(SQUAT_PACK_MAX_SIZE * uid_count); + uidbuf = t_malloc_no0(SQUAT_PACK_MAX_SIZE * uid_count); else uidbuf = i_malloc(SQUAT_PACK_MAX_SIZE * uid_count); bufp = uidbuf; diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index f1752a21db..35b4f74fa3 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -542,7 +542,7 @@ static const char *client_stats(struct client *client) struct var_expand_table *tab; string_t *str; - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = dec2str(client->top_bytes); diff --git a/src/pop3/pop3-commands.c b/src/pop3/pop3-commands.c index 2fe8a96483..320d4c1050 100644 --- a/src/pop3/pop3-commands.c +++ b/src/pop3/pop3-commands.c @@ -598,7 +598,7 @@ pop3_get_uid(struct client *client, struct mail *mail, string_t *str, return 0; } - tab = t_malloc(sizeof(static_tab)); + tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); tab[0].value = t_strdup_printf("%u", client->uid_validity); diff --git a/src/ssl-params/ssl-params.c b/src/ssl-params/ssl-params.c index be44693d61..04ba39e569 100644 --- a/src/ssl-params/ssl-params.c +++ b/src/ssl-params/ssl-params.c @@ -214,7 +214,7 @@ static int ssl_params_read(struct ssl_params *param) return -1; } - buffer = t_malloc(st.st_size); + buffer = t_malloc_no0(st.st_size); ret = read_full(fd, buffer, st.st_size); if (ret < 0) i_error("read(%s) failed: %m", param->path);