/* 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;
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)];
{
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;
{
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;
{
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;
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);
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);
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);
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);
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);
}
/* 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);
{
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;
{
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;
{
unsigned char *digest;
- digest = t_malloc(LM_HASH_SIZE);
+ digest = t_malloc_no0(LM_HASH_SIZE);
lm_hash(plaintext, digest);
*raw_password_r = digest;
{
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;
{
unsigned char *digest;
- digest = t_malloc(MD5_RESULTLEN);
+ digest = t_malloc_no0(MD5_RESULTLEN);
password_generate_rpa(plaintext, digest);
*raw_password_r = digest;
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;
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))) {
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;
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));
/* 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);
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] = ' ';
/* 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, "&-");
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);
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;
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";
} 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, '@');
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;
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)
/* 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;
};
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;
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] =
return ret;
}
-void *t_malloc(size_t size)
+void *t_malloc_no0(size_t size)
{
return t_malloc_real(size, TRUE);
}
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
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';
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';
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;
}
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;
}
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++) {
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;
int pos;
pos = MAX_INT_STRLEN;
- buffer = t_malloc(pos);
+ buffer = t_malloc_no0(pos);
buffer[--pos] = '\0';
do {
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 */
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);
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);
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 */
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);
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 &&
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 = '*';
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);
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);
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++)
{
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));
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);
};
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);
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 = "";
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);
/* 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 {
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] &&
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]);
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;
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);
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);
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);