# HG changeset patch # User Timo Sirainen # Date 1097257907 -10800 # Node ID f1e9f3ec81354dca1d523c98a3e52ee03d58a242 # Parent bd250ef1c09ae164991573a9de5d20515e3efb51 Buffer API change: we no longer support limited sized buffers where writes past limit wouldn't kill the process. They weren't used hardly anywhere, they could have hidden bugs and the code for handling them was too complex. This also changed base64 and hex-binary APIs. diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/auth-master-connection.c --- a/src/auth/auth-master-connection.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/auth-master-connection.c Fri Oct 08 20:51:47 2004 +0300 @@ -55,7 +55,7 @@ char *p; buf = buffer_create_dynamic(pool_datastack_create(), - sizeof(reply) + 256, (size_t)-1); + sizeof(reply) + 256); memset(&reply, 0, sizeof(reply)); buffer_append(buf, &reply, sizeof(reply)); @@ -219,7 +219,7 @@ reply.server_pid = master->pid; - buf = buffer_create_dynamic(default_pool, 128, (size_t)-1); + buf = buffer_create_dynamic(default_pool, 128); for (list = mech_modules; list != NULL; list = list->next) reply.mech_count++; @@ -273,8 +273,7 @@ conn->refcount = 1; conn->pid = pid; conn->fd = fd; - conn->listeners_buf = - buffer_create_dynamic(default_pool, 64, (size_t)-1); + conn->listeners_buf = buffer_create_dynamic(default_pool, 64); if (fd != -1) auth_master_connection_set_fd(conn, fd); master_get_handshake_reply(conn); diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/main.c --- a/src/auth/main.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/main.c Fri Oct 08 20:51:47 2004 +0300 @@ -204,7 +204,7 @@ lib_init_signals(sig_quit); mech_init(); - masters_buf = buffer_create_dynamic(default_pool, 64, (size_t)-1); + masters_buf = buffer_create_dynamic(default_pool, 64); env = getenv("AUTH_PROCESS"); standalone = env == NULL; diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/mech-cram-md5.c --- a/src/auth/mech-cram-md5.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/mech-cram-md5.c Fri Oct 08 20:51:47 2004 +0300 @@ -62,7 +62,7 @@ buffer_create_data(pool_datastack_create(), context_digest, sizeof(context_digest)); - if (hex_to_binary(credentials, context_digest_buf) <= 0) + if (hex_to_binary(credentials, context_digest_buf) < 0) return FALSE; hmac_md5_set_cram_context(&ctx, context_digest); diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/mech-digest-md5.c --- a/src/auth/mech-digest-md5.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/mech-digest-md5.c Fri Oct 08 20:51:47 2004 +0300 @@ -74,8 +74,8 @@ random_fill(nonce, sizeof(nonce)); t_push(); - buf = buffer_create_static(pool_datastack_create(), - MAX_BASE64_ENCODED_SIZE(sizeof(nonce))+1); + buf = buffer_create_static_hard(pool_datastack_create(), + MAX_BASE64_ENCODED_SIZE(sizeof(nonce))+1); base64_encode(nonce, sizeof(nonce), buf); buffer_append_c(buf, '\0'); @@ -123,7 +123,7 @@ digest_buf = buffer_create_data(pool_datastack_create(), digest, sizeof(digest)); - if (hex_to_binary(credentials, digest_buf) <= 0) + if (hex_to_binary(credentials, digest_buf) < 0) return FALSE; /* diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/mech-rpa.c --- a/src/auth/mech-rpa.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/mech-rpa.c Fri Oct 08 20:51:47 2004 +0300 @@ -333,7 +333,7 @@ length = sizeof(rpa_oid) + 3 + RPA_SCHALLENGE_LEN + RPA_TIMESTAMP_LEN + 2 + realms_len; - buf = buffer_create_dynamic(auth->pool, length + 4, (size_t)-1); + buf = buffer_create_dynamic(auth->pool, length + 4); buffer_append_c(buf, ASN1_APPLICATION); buffer_append_asn1_length(buf, length); @@ -373,7 +373,7 @@ buffer_t *buf; unsigned char server_response[16]; - buf = buffer_create_dynamic(auth->pool, length + 4, (size_t)-1); + buf = buffer_create_dynamic(auth->pool, length + 4); buffer_append_c(buf, ASN1_APPLICATION); buffer_append_asn1_length(buf, length); diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/mech.c --- a/src/auth/mech.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/mech.c Fri Oct 08 20:51:47 2004 +0300 @@ -205,7 +205,7 @@ { buffer_t *buf; - buf = buffer_create_dynamic(pool_datastack_create(), 256, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 256); reply->username_idx = 0; buffer_append(buf, auth_request->user, strlen(auth_request->user)+1); @@ -480,8 +480,7 @@ #endif ssl_require_client_cert = getenv("SSL_REQUIRE_CLIENT_CERT") != NULL; - auth_failures_buf = - buffer_create_dynamic(default_pool, 1024, (size_t)-1); + auth_failures_buf = buffer_create_dynamic(default_pool, 1024); to_auth_failures = timeout_add(2000, auth_failure_timeout, NULL); } diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/passdb-checkpassword.c --- a/src/auth/passdb-checkpassword.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/passdb-checkpassword.c Fri Oct 08 20:51:47 2004 +0300 @@ -162,8 +162,7 @@ } else { if (request->input_buf == NULL) { request->input_buf = - buffer_create_dynamic(default_pool, - 512, (size_t)-1); + buffer_create_dynamic(default_pool, 512); } buffer_append(request->input_buf, buf, ret); } @@ -182,12 +181,19 @@ size_t size; ssize_t ret; - buf = buffer_create_static(pool_datastack_create(), 512+1); + buf = buffer_create_dynamic(pool_datastack_create(), 512+1); buffer_append(buf, auth_request->user, strlen(auth_request->user)+1); buffer_append(buf, request->password, strlen(request->password)+1); buffer_append_c(buf, '\0'); data = buffer_get_data(buf, &size); + if (size > 512) { + i_error("checkpassword: output larger than 512 bytes: " + "%"PRIuSIZE_T, size); + checkpassword_request_close(request); + return; + } + ret = write(request->fd_out, data + request->write_pos, size - request->write_pos); if (ret <= 0) { diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/password-scheme-rpa.c --- a/src/auth/password-scheme-rpa.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/password-scheme-rpa.c Fri Oct 08 20:51:47 2004 +0300 @@ -13,7 +13,7 @@ */ void *ucs2be_str(pool_t pool, const char *str, size_t *size) { - buffer_t *buf = buffer_create_dynamic(pool, 32, (size_t)-1); + buffer_t *buf = buffer_create_dynamic(pool, 32); while (*str) { buffer_append_c(buf, '\0'); diff -r bd250ef1c09a -r f1e9f3ec8135 src/auth/password-scheme.c --- a/src/auth/password-scheme.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/auth/password-scheme.c Fri Oct 08 20:51:47 2004 +0300 @@ -160,14 +160,15 @@ unsigned char sha1_digest[SHA1_RESULTLEN]; const char *data; buffer_t *buf; - size_t size; + size_t size, password_len; sha1_get_digest(plaintext, strlen(plaintext), sha1_digest); - buf = buffer_create_static(pool_datastack_create(), - MAX_BASE64_DECODED_SIZE(strlen(password)+1)); + password_len = strlen(password); + buf = buffer_create_static_hard(pool_datastack_create(), + MAX_BASE64_DECODED_SIZE(password_len)); - if (base64_decode(password, strlen(password), NULL, buf) <= 0) { + if (base64_decode(password, password_len, NULL, buf) < 0) { i_error("sha1_verify(%s): failed decoding SHA base64", user); return 0; } @@ -207,14 +208,15 @@ unsigned char sha1_digest[SHA1_RESULTLEN]; buffer_t *buf; const char *data; - size_t size; + size_t size, password_len; struct sha1_ctxt ctx; /* format: base64-encoded MD5 hash and salt */ - buf = buffer_create_static(pool_datastack_create(), - MAX_BASE64_DECODED_SIZE(strlen(password)+1)); + password_len = strlen(password); + buf = buffer_create_static_hard(pool_datastack_create(), + MAX_BASE64_DECODED_SIZE(password_len)); - if (base64_decode(password, strlen(password), NULL, buf) <= 0) { + if (base64_decode(password, password_len, NULL, buf) < 0) { i_error("ssha_verify(%s): failed decoding SSHA base64", user); return 0; } @@ -258,14 +260,15 @@ unsigned char md5_digest[16]; buffer_t *buf; const char *data; - size_t size; + size_t size, password_len; struct md5_context ctx; /* format: base64-encoded MD5 hash and salt */ - buf = buffer_create_static(pool_datastack_create(), - MAX_BASE64_DECODED_SIZE(strlen(password)+1)); + password_len = strlen(password); + buf = buffer_create_static_hard(pool_datastack_create(), + MAX_BASE64_DECODED_SIZE(password_len)); - if (base64_decode(password, strlen(password), NULL, buf) <= 0) { + if (base64_decode(password, password_len, NULL, buf) < 0) { i_error("smd5_verify(%s): failed decoding SMD5 base64", user); return 0; } @@ -378,14 +381,15 @@ unsigned char md5_digest[16]; buffer_t *buf; const char *data; - size_t size; + size_t size, password_len; md5_get_digest(plaintext, strlen(plaintext), md5_digest); - buf = buffer_create_static(pool_datastack_create(), - MAX_BASE64_DECODED_SIZE(strlen(password)+1)); + password_len = strlen(password); + buf = buffer_create_static_hard(pool_datastack_create(), + MAX_BASE64_DECODED_SIZE(password_len)); - if (base64_decode(password, strlen(password), NULL, buf) <= 0) { + if (base64_decode(password, password_len, NULL, buf) < 0) { i_error("ldap_md5_verify(%s): failed decoding MD5 base64", user); return 0; @@ -464,7 +468,7 @@ const char *symbol; #endif - schemes_buf = buffer_create_dynamic(default_pool, 128, (size_t)-1); + schemes_buf = buffer_create_dynamic(default_pool, 128); for (s = default_schemes; s->name != NULL; s++) buffer_append(schemes_buf, s, sizeof(*s)); diff -r bd250ef1c09a -r f1e9f3ec8135 src/imap-login/client-authenticate.c --- a/src/imap-login/client-authenticate.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/imap-login/client-authenticate.c Fri Oct 08 20:51:47 2004 +0300 @@ -98,8 +98,7 @@ t_push(); - buf = buffer_create_dynamic(pool_datastack_create(), - size*2, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), size*2); buffer_append(buf, "+ ", 2); base64_encode(data, size, buf); buffer_append(buf, "\r\n", 2); @@ -284,7 +283,7 @@ linelen = strlen(line); buf = buffer_create_static_hard(pool_datastack_create(), linelen); - if (base64_decode(line, linelen, NULL, buf) <= 0) { + if (base64_decode(line, linelen, NULL, buf) < 0) { /* failed */ client_auth_abort(client, "Invalid base64 data"); } else if (client->common.auth_request == NULL) { diff -r bd250ef1c09a -r f1e9f3ec8135 src/imap/cmd-sort.c --- a/src/imap/cmd-sort.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/imap/cmd-sort.c Fri Oct 08 20:51:47 2004 +0300 @@ -38,8 +38,7 @@ } buf = buffer_create_dynamic(pool_datastack_create(), - 32 * sizeof(enum mail_sort_type), - (size_t)-1); + 32 * sizeof(enum mail_sort_type)); while (args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING) { const char *arg = IMAP_ARG_STR(args); diff -r bd250ef1c09a -r f1e9f3ec8135 src/imap/commands-util.c --- a/src/imap/commands-util.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/imap/commands-util.c Fri Oct 08 20:51:47 2004 +0300 @@ -184,7 +184,7 @@ size_t size, i; memset(flags, 0, sizeof(*flags)); - buffer = buffer_create_dynamic(client->cmd_pool, 256, (size_t)-1); + buffer = buffer_create_dynamic(client->cmd_pool, 256); while (args->type != IMAP_ARG_EOL) { if (args->type != IMAP_ARG_ATOM) { diff -r bd250ef1c09a -r f1e9f3ec8135 src/imap/commands.c --- a/src/imap/commands.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/imap/commands.c Fri Oct 08 20:51:47 2004 +0300 @@ -136,7 +136,7 @@ void commands_init(void) { cmdbuf = buffer_create_dynamic(system_pool, - sizeof(struct command) * 64, (size_t)-1); + sizeof(struct command) * 64); cmdbuf_unsorted = FALSE; command_register_array(imap4rev1_commands, IMAP4REV1_COMMANDS_COUNT); diff -r bd250ef1c09a -r f1e9f3ec8135 src/imap/imap-fetch.c --- a/src/imap/imap-fetch.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/imap/imap-fetch.c Fri Oct 08 20:51:47 2004 +0300 @@ -30,10 +30,8 @@ void *data; size_t size; - if (fetch_handlers == NULL) { - fetch_handlers = buffer_create_dynamic(default_pool, - 128, (size_t)-1); - } + if (fetch_handlers == NULL) + fetch_handlers = buffer_create_dynamic(default_pool, 128); buffer_append(fetch_handlers, handlers, sizeof(*handlers) * count); data = buffer_get_modifyable_data(fetch_handlers, &size); @@ -93,10 +91,8 @@ ctx->cur_str = str_new(default_pool, 8192); ctx->seen_flag.flags = MAIL_SEEN; - ctx->all_headers_buf = - buffer_create_dynamic(client->cmd_pool, 128, (size_t)-1); - ctx->handlers = - buffer_create_dynamic(client->cmd_pool, 128, (size_t)-1); + ctx->all_headers_buf = buffer_create_dynamic(client->cmd_pool, 128); + ctx->handlers = buffer_create_dynamic(client->cmd_pool, 128); return ctx; } diff -r bd250ef1c09a -r f1e9f3ec8135 src/imap/imap-sort.c --- a/src/imap/imap-sort.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/imap/imap-sort.c Fri Oct 08 20:51:47 2004 +0300 @@ -240,8 +240,7 @@ ctx->box = client->mailbox; ctx->output = client->output; ctx->sort_buffer = buffer_create_dynamic(system_pool, - 128 * ctx->sort_element_size, - (size_t)-1); + 128 * ctx->sort_element_size); ctx->str = t_str_new(STRBUF_SIZE); str_append(ctx->str, "* SORT"); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-auth/auth-client.c --- a/src/lib-auth/auth-client.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-auth/auth-client.c Fri Oct 08 20:51:47 2004 +0300 @@ -25,8 +25,7 @@ client = i_new(struct auth_client, 1); client->pid = client_pid; client->socket_paths = i_strdup(socket_paths); - client->available_auth_mechs = - buffer_create_dynamic(default_pool, 128, (size_t)-1); + client->available_auth_mechs = buffer_create_dynamic(default_pool, 128); client->ext_input_add = add_func; client->ext_input_remove = remove_func; diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-auth/auth-server-connection.c --- a/src/lib-auth/auth-server-connection.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-auth/auth-server-connection.c Fri Oct 08 20:51:47 2004 +0300 @@ -58,7 +58,7 @@ } buf = buffer_create_dynamic(conn->pool, sizeof(mech_desc) * - handshake->mech_count, (size_t)-1); + handshake->mech_count); for (i = 0; i < handshake->mech_count; i++) { memcpy(&handshake_mech_desc, data + sizeof(handshake_mech_desc) * i, diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-auth/auth-server-request.c --- a/src/lib-auth/auth-server-request.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-auth/auth-server-request.c Fri Oct 08 20:51:47 2004 +0300 @@ -86,7 +86,7 @@ auth_request.ip_family = request->local_ip.family; t_push(); - buf = buffer_create_dynamic(pool_datastack_create(), 256, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 256); buffer_set_used_size(buf, sizeof(auth_request)); if (auth_request.ip_family != 0) { diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-charset/charset-utf8.c --- a/src/lib-charset/charset-utf8.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-charset/charset-utf8.c Fri Oct 08 20:51:47 2004 +0300 @@ -22,7 +22,7 @@ { buffer_t *dest; - dest = buffer_create_dynamic(pool_datastack_create(), size, (size_t)-1); + dest = buffer_create_dynamic(pool_datastack_create(), size); _charset_utf8_ucase(data, size, dest, 0); if (utf8_size_r != NULL) *utf8_size_r = buffer_get_used_size(dest); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-imap/imap-base-subject.c --- a/src/lib-imap/imap-base-subject.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-imap/imap-base-subject.c Fri Oct 08 20:51:47 2004 +0300 @@ -241,7 +241,7 @@ *is_reply_or_forward_r = FALSE; subject_len = strlen(subject); - buf = buffer_create_dynamic(pool, subject_len, (size_t)-1); + buf = buffer_create_dynamic(pool, subject_len); /* (1) Convert any RFC 2047 encoded-words in the subject to UTF-8. Convert all tabs and continuations to space. diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-cache-compress.c --- a/src/lib-index/mail-cache-compress.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-cache-compress.c Fri Oct 08 20:51:47 2004 +0300 @@ -135,8 +135,8 @@ o_stream_send(output, &hdr, sizeof(hdr)); memset(&ctx, 0, sizeof(ctx)); - ctx.buffer = buffer_create_dynamic(default_pool, 4096, (size_t)-1); - ctx.field_seen = buffer_create_dynamic(default_pool, 64, (size_t)-1); + ctx.buffer = buffer_create_dynamic(default_pool, 4096); + ctx.field_seen = buffer_create_dynamic(default_pool, 64); ctx.field_seen_value = 0; mail_index_reset_cache(t, hdr.file_seq); @@ -181,8 +181,7 @@ cache->field_file_map[i] = (uint32_t)-1; t_push(); - buffer = buffer_create_dynamic(pool_datastack_create(), - 256, (size_t)-1); + buffer = buffer_create_dynamic(pool_datastack_create(), 256); mail_cache_header_fields_get(cache, buffer); o_stream_send(output, buffer_get_data(buffer, NULL), buffer_get_used_size(buffer)); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-cache-fields.c --- a/src/lib-index/mail-cache-fields.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-cache-fields.c Fri Oct 08 20:51:47 2004 +0300 @@ -281,8 +281,7 @@ } t_push(); - buffer = buffer_create_dynamic(pool_datastack_create(), - 256, (size_t)-1); + buffer = buffer_create_dynamic(pool_datastack_create(), 256); copy_to_buf(cache, buffer, offsetof(struct mail_cache_field_private, last_used), diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-cache-lookup.c --- a/src/lib-index/mail-cache-lookup.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-cache-lookup.c Fri Oct 08 20:51:47 2004 +0300 @@ -430,7 +430,7 @@ ctx.fields_count = fields_count; ctx.max_field = 0; - buf = buffer_create_dynamic(pool_datastack_create(), 32, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 32); for (i = 0; i < fields_count; i++) { i_assert(fields[i] < cache->fields_count); if (cache->field_file_map[fields[i]] == (unsigned int)-1) { @@ -447,8 +447,7 @@ } ctx.fields_found = buffer_get_modifyable_data(buf, NULL); - ctx.data = buffer_create_dynamic(pool_datastack_create(), - 256, (size_t)-1); + ctx.data = buffer_create_dynamic(pool_datastack_create(), 256); /* we need to return them in sorted order. create array: { line number -> cache file offset } */ diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-cache-transaction.c --- a/src/lib-index/mail-cache-transaction.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-cache-transaction.c Fri Oct 08 20:51:47 2004 +0300 @@ -45,8 +45,7 @@ ctx->cache = view->cache; ctx->view = view; ctx->trans = t; - ctx->reservations = - buffer_create_dynamic(system_pool, 256, (size_t)-1); + ctx->reservations = buffer_create_dynamic(system_pool, 256); if (!MAIL_CACHE_IS_UNUSABLE(ctx->cache)) ctx->cache_file_seq = ctx->cache->hdr->file_seq; @@ -484,10 +483,8 @@ sizeof(ctx->prev_seq)); ctx->prev_pos = size; } else if (ctx->cache_data == NULL) { - ctx->cache_data = - buffer_create_dynamic(system_pool, 32768, (size_t)-1); - ctx->cache_data_seq = - buffer_create_dynamic(system_pool, 256, (size_t)-1); + ctx->cache_data = buffer_create_dynamic(system_pool, 32768); + ctx->cache_data_seq = buffer_create_dynamic(system_pool, 256); } memset(&new_rec, 0, sizeof(new_rec)); @@ -589,8 +586,7 @@ } t_push(); - buffer = buffer_create_dynamic(pool_datastack_create(), - 256, (size_t)-1); + buffer = buffer_create_dynamic(pool_datastack_create(), 256); mail_cache_header_fields_get(cache, buffer); data = buffer_get_data(buffer, &size); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-cache.c --- a/src/lib-index/mail-cache.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-cache.c Fri Oct 08 20:51:47 2004 +0300 @@ -333,12 +333,10 @@ view = i_new(struct mail_cache_view, 1); view->cache = cache; view->view = iview; - view->offsets_buf = - buffer_create_dynamic(default_pool, 128, (size_t)-1); + view->offsets_buf = buffer_create_dynamic(default_pool, 128); view->cached_exists_buf = buffer_create_dynamic(default_pool, - cache->file_fields_count + 10, - (size_t)-1); + cache->file_fields_count + 10); return view; } diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-index-sync.c --- a/src/lib-index/mail-index-sync.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-index-sync.c Fri Oct 08 20:51:47 2004 +0300 @@ -309,10 +309,8 @@ /* we need to have all the transactions sorted to optimize caller's mailbox access patterns */ - ctx->expunges_buf = buffer_create_dynamic(default_pool, - 1024, (size_t)-1); - ctx->updates_buf = buffer_create_dynamic(default_pool, - 1024, (size_t)-1); + ctx->expunges_buf = buffer_create_dynamic(default_pool, 1024); + ctx->updates_buf = buffer_create_dynamic(default_pool, 1024); if (mail_index_sync_read_and_sort(ctx, sync_recent) < 0) { mail_index_sync_rollback(ctx); return -1; diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-index-transaction.c --- a/src/lib-index/mail-index-transaction.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-index-transaction.c Fri Oct 08 20:51:47 2004 +0300 @@ -199,10 +199,8 @@ t->log_updates = TRUE; - if (t->appends == NULL) { - t->appends = buffer_create_dynamic(default_pool, - 4096, (size_t)-1); - } + if (t->appends == NULL) + t->appends = buffer_create_dynamic(default_pool, 4096); /* sequence number is visible only inside given view, so let it generate it */ @@ -256,8 +254,7 @@ /* expunges is a sorted array of {seq1, seq2, ..}, .. */ if (t->expunges == NULL) { - t->expunges = buffer_create_dynamic(default_pool, - 1024, (size_t)-1); + t->expunges = buffer_create_dynamic(default_pool, 1024); buffer_append(t->expunges, &exp, sizeof(exp)); return; } @@ -447,10 +444,8 @@ mail_index_transaction_get_last(t, &update); - if (t->updates == NULL) { - t->updates = buffer_create_dynamic(default_pool, - 4096, (size_t)-1); - } + if (t->updates == NULL) + t->updates = buffer_create_dynamic(default_pool, 4096); data = buffer_get_modifyable_data(t->updates, &size); size /= sizeof(*data); @@ -543,7 +538,7 @@ size_t pos; if (*buffer == NULL) { - *buffer = buffer_create_dynamic(default_pool, 1024, (size_t)-1); + *buffer = buffer_create_dynamic(default_pool, 1024); buffer_append(*buffer, &seq, sizeof(seq)); buffer_append(*buffer, record, record_size); return FALSE; @@ -694,10 +689,8 @@ (ext->record_size == record_size && ext->record_align == record_align)); - if (t->ext_resizes == NULL) { - t->ext_resizes = - buffer_create_dynamic(default_pool, 128, (size_t)-1); - } + if (t->ext_resizes == NULL) + t->ext_resizes = buffer_create_dynamic(default_pool, 128); intro.hdr_size = hdr_size; intro.record_size = record_size; @@ -745,10 +738,8 @@ record_size = ext[ext_id].record_size; } - if (t->ext_rec_updates == NULL) { - t->ext_rec_updates = - buffer_create_dynamic(default_pool, 128, (size_t)-1); - } + if (t->ext_rec_updates == NULL) + t->ext_rec_updates = buffer_create_dynamic(default_pool, 128); buf = buffer_get_space_unsafe(t->ext_rec_updates, ext_id * sizeof(buffer_t *), sizeof(buffer_t *)); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-index-view-sync.c --- a/src/lib-index/mail-index-view-sync.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-index-view-sync.c Fri Oct 08 20:51:47 2004 +0300 @@ -30,7 +30,7 @@ size_t size; int ret; - *expunges_r = buffer_create_dynamic(default_pool, 512, (size_t)-1); + *expunges_r = buffer_create_dynamic(default_pool, 512); /* with mask 0 we don't get anything, we'll just read the expunges while seeking to end */ @@ -363,10 +363,8 @@ uint32_t log_file_seq, uoff_t log_file_offset) { - if (view->log_syncs == NULL) { - view->log_syncs = buffer_create_dynamic(default_pool, - 128, (size_t)-1); - } + if (view->log_syncs == NULL) + view->log_syncs = buffer_create_dynamic(default_pool, 128); buffer_append(view->log_syncs, &log_file_offset, sizeof(log_file_offset)); buffer_append(view->log_syncs, &log_file_seq, sizeof(log_file_seq)); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-index-view.c --- a/src/lib-index/mail-index-view.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-index-view.c Fri Oct 08 20:51:47 2004 +0300 @@ -158,8 +158,7 @@ return; } } else { - view->map_refs = - buffer_create_dynamic(default_pool, 128, (size_t)-1); + view->map_refs = buffer_create_dynamic(default_pool, 128); } map->refcount++; diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-index.c --- a/src/lib-index/mail-index.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-index.c Fri Oct 08 20:51:47 2004 +0300 @@ -27,8 +27,7 @@ index->fd = -1; index->extension_pool = pool_alloconly_create("extension", 256); - index->extensions = - buffer_create_dynamic(index->extension_pool, 64, (size_t)-1); + index->extensions = buffer_create_dynamic(index->extension_pool, 64); index->mode = 0600; index->gid = (gid_t)-1; @@ -99,10 +98,9 @@ p_clear(map->extension_pool); } - map->extensions = buffer_create_dynamic(map->extension_pool, - ext_size, (size_t)-1); - map->ext_id_map = buffer_create_dynamic(map->extension_pool, - ext_id_map_size, (size_t)-1); + map->extensions = buffer_create_dynamic(map->extension_pool, ext_size); + map->ext_id_map = + buffer_create_dynamic(map->extension_pool, ext_id_map_size); } uint32_t mail_index_map_lookup_ext(struct mail_index_map *map, const char *name) @@ -471,8 +469,7 @@ if (map->buffer == NULL) { map->buffer = buffer_create_dynamic(default_pool, - records_size, - (size_t)-1); + records_size); } /* @UNSAFE */ @@ -582,8 +579,7 @@ map = i_new(struct mail_index_map, 1); map->refcount = 1; map->hdr_copy_buf = - buffer_create_dynamic(default_pool, - sizeof(*map->hdr), (size_t)-1); + buffer_create_dynamic(default_pool, sizeof(*map->hdr)); } else if (MAIL_INDEX_MAP_IS_IN_MEMORY(map)) { if (map->write_to_disk) { /* we have modified this mapping and it's waiting to @@ -651,7 +647,7 @@ mem_map = i_new(struct mail_index_map, 1); mem_map->refcount = 1; - mem_map->buffer = buffer_create_dynamic(default_pool, size, (size_t)-1); + mem_map->buffer = buffer_create_dynamic(default_pool, size); if (map->hdr->record_size == new_record_size) buffer_append(mem_map->buffer, map->records, size); else { @@ -668,9 +664,8 @@ mem_map->records = buffer_get_modifyable_data(mem_map->buffer, NULL); mem_map->records_count = map->records_count; - mem_map->hdr_copy_buf = buffer_create_dynamic(default_pool, - map->hdr->header_size, - (size_t)-1); + mem_map->hdr_copy_buf = + buffer_create_dynamic(default_pool, map->hdr->header_size); buffer_append(mem_map->hdr_copy_buf, map->hdr, map->hdr->header_size); hdr = buffer_get_modifyable_data(mem_map->hdr_copy_buf, NULL); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-index/mail-transaction-log.c --- a/src/lib-index/mail-transaction-log.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-index/mail-transaction-log.c Fri Oct 08 20:51:47 2004 +0300 @@ -727,8 +727,8 @@ } if (file->buffer == NULL) { - file->buffer = buffer_create_dynamic(default_pool, - LOG_PREFETCH, (size_t)-1); + file->buffer = + buffer_create_dynamic(default_pool, LOG_PREFETCH); file->buffer_offset = offset; } @@ -978,10 +978,8 @@ uint32_t ext_id; size_t pos; - if (t->ext_intros == NULL) { - t->ext_intros = buffer_create_dynamic(default_pool, - 128, (size_t)-1); - } + if (t->ext_intros == NULL) + t->ext_intros = buffer_create_dynamic(default_pool, 128); t_push(); name = t_strndup((const char *)(intro+1), intro->name_size); @@ -1138,7 +1136,7 @@ memset(&u, 0, sizeof(u)); u.new_file_seq = t->new_cache_file_seq; - buf = buffer_create_static(pool_datastack_create(), sizeof(u)); + buf = buffer_create_static_hard(pool_datastack_create(), sizeof(u)); buffer_append(buf, &u, sizeof(u)); return buf; } @@ -1153,7 +1151,7 @@ memset(&u, 0, sizeof(u)); - buf = buffer_create_dynamic(pool_datastack_create(), 256, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 256); for (offset = 0; offset <= sizeof(t->hdr_change); offset++) { if (offset < sizeof(t->hdr_change) && t->hdr_mask[offset]) { if (state == 0) { @@ -1238,7 +1236,7 @@ } /* and register them */ - buf = buffer_create_dynamic(pool_datastack_create(), 128, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 128); for (i = 0; i < size; i++) { if (intro[i].name_size != 0) { intro[i].name_size = strlen(ext[i].name); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-mail/istream-header-filter.c --- a/src/lib-mail/istream-header-filter.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-mail/istream-header-filter.c Fri Oct 08 20:51:47 2004 +0300 @@ -291,7 +291,7 @@ for (i = 0; i < headers_count; i++) mstream->headers[i] = p_strdup(pool, headers[i]); mstream->headers_count = headers_count; - mstream->hdr_buf = buffer_create_dynamic(pool, 1024, (size_t)-1); + mstream->hdr_buf = buffer_create_dynamic(pool, 1024); mstream->callback = callback; mstream->context = context; diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-mail/message-body-search.c --- a/src/lib-mail/message-body-search.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-mail/message-body-search.c Fri Oct 08 20:51:47 2004 +0300 @@ -213,10 +213,10 @@ const unsigned char *inbuf; buffer_t *outbuf; enum charset_result result; - size_t block_pos, inbuf_size, inbuf_left, ret; + size_t block_pos, inbuf_size, inbuf_left; - outbuf = buffer_create_static(pool_datastack_create(), - DECODE_BLOCK_SIZE); + outbuf = buffer_create_static_hard(pool_datastack_create(), + DECODE_BLOCK_SIZE); for (block_pos = 0; block_pos < buffer_get_used_size(block); ) { if (buffer_get_used_size(ctx->decode_buf) == 0) { /* we can use the buffer directly without copying */ @@ -226,9 +226,9 @@ } else { /* some characters already in buffer, ie. last conversion contained partial data */ - block_pos += buffer_append_buf(ctx->decode_buf, - block, block_pos, - (size_t)-1); + buffer_append_buf(ctx->decode_buf, block, + block_pos, block->used); + block_pos += block->used; inbuf = buffer_get_data(ctx->decode_buf, &inbuf_size); } @@ -250,11 +250,9 @@ break; case CHARSET_RET_INCOMPLETE_INPUT: /* save the partial sequence to buffer */ - ret = buffer_write(ctx->decode_buf, 0, - inbuf + inbuf_size, inbuf_left); - i_assert(ret == inbuf_left); - - buffer_set_used_size(ctx->decode_buf, ret); + buffer_write(ctx->decode_buf, 0, + inbuf + inbuf_size, inbuf_left); + buffer_set_used_size(ctx->decode_buf, inbuf_left); break; case CHARSET_RET_INVALID_INPUT: @@ -294,7 +292,8 @@ if (ctx->translation == NULL) ctx->translation = charset_to_utf8_begin("ascii", NULL); - ctx->decode_buf = buffer_create_static(pool_datastack_create(), 256); + ctx->decode_buf = + buffer_create_static_hard(pool_datastack_create(), 256); ctx->match_buf = buffer_create_static_hard(pool_datastack_create(), sizeof(size_t) * ctx->body_ctx->key_len); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-mail/message-parser.c Fri Oct 08 20:51:47 2004 +0300 @@ -703,7 +703,7 @@ else { ctx->value_buf = buffer_create_dynamic(default_pool, - 4096, (size_t)-1); + 4096); } buffer_append(ctx->value_buf, line->value, line->value_len); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-mail/quoted-printable.c --- a/src/lib-mail/quoted-printable.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-mail/quoted-printable.c Fri Oct 08 20:51:47 2004 +0300 @@ -49,7 +49,7 @@ hexbuf[0] = src[src_pos+1]; hexbuf[1] = src[src_pos+2]; - if (hex_to_binary(hexbuf, dest) == 1) { + if (hex_to_binary(hexbuf, dest) == 0) { src_pos += 2; next = src_pos+1; } else { diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-ntlm/ntlm-encrypt.c --- a/src/lib-ntlm/ntlm-encrypt.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-ntlm/ntlm-encrypt.c Fri Oct 08 20:51:47 2004 +0300 @@ -25,7 +25,7 @@ { buffer_t *wstr; - wstr = buffer_create_dynamic(unsafe_data_stack_pool, 32, (size_t)-1); + wstr = buffer_create_dynamic(unsafe_data_stack_pool, 32); for ( ; *src; src++) { buffer_append_c(wstr, ucase ? i_toupper(*src) : *src); buffer_append_c(wstr, '\0'); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-ntlm/ntlm-message.c --- a/src/lib-ntlm/ntlm-message.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-ntlm/ntlm-message.c Fri Oct 08 20:51:47 2004 +0300 @@ -136,8 +136,7 @@ uint32_t flags = ntlmssp_flags(read_le32(&request->flags)); struct ntlmssp_challenge c; - buf = buffer_create_dynamic(pool, sizeof(struct ntlmssp_challenge), - (size_t)-1); + buf = buffer_create_dynamic(pool, sizeof(struct ntlmssp_challenge)); memset(&c, 0, sizeof(c)); write_le64(&c.magic, NTLMSSP_MAGIC); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-storage/index/index-mail-headers.c --- a/src/lib-storage/index/index-mail-headers.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-storage/index/index-mail-headers.c Fri Oct 08 20:51:47 2004 +0300 @@ -54,7 +54,7 @@ match = buffer_get_data(mail->header_match, &match_size); header = buffer_get_data(mail->header_data, NULL); - buf = buffer_create_dynamic(pool_datastack_create(), 256, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 256); for (i = match_idx = 0; i < size; i = j) { while (match_idx < lines[i].field_idx && @@ -125,14 +125,10 @@ mail->header_seq = mail->data.seq; if (mail->header_data == NULL) { - mail->header_data = - buffer_create_dynamic(default_pool, 4096, (size_t)-1); - mail->header_lines = - buffer_create_dynamic(default_pool, 256, (size_t)-1); - mail->header_match = - buffer_create_dynamic(default_pool, 64, (size_t)-1); - mail->header_offsets = - buffer_create_dynamic(default_pool, 256, (size_t)-1); + mail->header_data = buffer_create_dynamic(default_pool, 4096); + mail->header_lines = buffer_create_dynamic(default_pool, 256); + mail->header_match = buffer_create_dynamic(default_pool, 64); + mail->header_offsets = buffer_create_dynamic(default_pool, 256); } else { buffer_set_used_size(mail->header_data, 0); buffer_set_used_size(mail->header_lines, 0); @@ -586,7 +582,7 @@ headers = sorted_headers; } - buf = buffer_create_dynamic(pool_datastack_create(), 128, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), 128); for (i = 0; i < size; i++) { header_field.name = t_strconcat("hdr.", headers[i], NULL); buffer_append(buf, &header_field, sizeof(header_field)); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-storage/index/index-mail.c --- a/src/lib-storage/index/index-mail.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-storage/index/index-mail.c Fri Oct 08 20:51:47 2004 +0300 @@ -40,8 +40,7 @@ const char *error; t_push(); - part_buf = buffer_create_dynamic(pool_datastack_create(), - 128, (size_t)-1); + part_buf = buffer_create_dynamic(pool_datastack_create(), 128); if (mail_cache_lookup_field(mail->trans->cache_view, part_buf, mail->data.seq, cache_fields[MAIL_CACHE_MESSAGEPART].idx) <= 0) { @@ -393,8 +392,7 @@ (decision != MAIL_CACHE_DECISION_NO || need_parts || (mail->wanted_fields & MAIL_FETCH_MESSAGE_PARTS) != 0)) { t_push(); - buffer = buffer_create_dynamic(pool_datastack_create(), - 1024, (size_t)-1); + buffer = buffer_create_dynamic(pool_datastack_create(), 1024); message_part_serialize(mail->data.parts, buffer); buf_data = buffer_get_data(buffer, &buf_size); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-storage/index/index-sync.c --- a/src/lib-storage/index/index-sync.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-storage/index/index-sync.c Fri Oct 08 20:51:47 2004 +0300 @@ -21,8 +21,7 @@ size_t dest_idx; if (ibox->recent_flags_start_seq == 0) { - ibox->recent_flags = - buffer_create_dynamic(default_pool, 128, (size_t)-1); + ibox->recent_flags = buffer_create_dynamic(default_pool, 128); ibox->recent_flags_start_seq = seq; } else if (seq < ibox->recent_flags_start_seq) { dest_idx = ibox->recent_flags_start_seq - seq; diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-storage/index/maildir/maildir-uidlist.c --- a/src/lib-storage/index/maildir/maildir-uidlist.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Fri Oct 08 20:51:47 2004 +0300 @@ -132,8 +132,7 @@ uidlist->fname = i_strconcat(ibox->control_dir, "/" MAILDIR_UIDLIST_NAME, NULL); uidlist->lock_fd = -1; - uidlist->record_buf = - buffer_create_dynamic(default_pool, 512, (size_t)-1); + uidlist->record_buf = buffer_create_dynamic(default_pool, 512); uidlist->files = hash_create(default_pool, default_pool, 4096, maildir_hash, maildir_cmp); @@ -581,7 +580,7 @@ maildir_hash, maildir_cmp); size = buffer_get_used_size(uidlist->record_buf); - ctx->record_buf = buffer_create_dynamic(default_pool, size, (size_t)-1); + ctx->record_buf = buffer_create_dynamic(default_pool, size); return ctx; } diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-storage/index/mbox/mbox-sync.c --- a/src/lib-storage/index/mbox/mbox-sync.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync.c Fri Oct 08 20:51:47 2004 +0300 @@ -1305,8 +1305,8 @@ sync_ctx.sync_view = sync_view; sync_ctx.t = mail_index_transaction_begin(sync_view, FALSE); - sync_ctx.mails = buffer_create_dynamic(default_pool, 4096, (size_t)-1); - sync_ctx.syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1); + sync_ctx.mails = buffer_create_dynamic(default_pool, 4096); + sync_ctx.syncs = buffer_create_dynamic(default_pool, 256); ret = mail_index_get_header(sync_view, &sync_ctx.hdr); i_assert(ret == 0); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib-storage/mail-search.c --- a/src/lib-storage/mail-search.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib-storage/mail-search.c Fri Oct 08 20:51:47 2004 +0300 @@ -163,8 +163,7 @@ *have_headers = *have_body = have_text = FALSE; - headers = buffer_create_dynamic(pool_datastack_create(), - 128, (size_t)-1); + headers = buffer_create_dynamic(pool_datastack_create(), 128); for (; args != NULL; args = args->next) { search_arg_analyze(args, headers, have_headers, have_body, &have_text); diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/base64.c --- a/src/lib/base64.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/base64.c Fri Oct 08 20:51:47 2004 +0300 @@ -46,7 +46,7 @@ static const char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -int base64_encode(const void *src, size_t src_size, buffer_t *dest) +void base64_encode(const void *src, size_t src_size, buffer_t *dest) { const unsigned char *src_c = src; size_t src_pos; @@ -54,36 +54,28 @@ for (src_pos = 0; src_pos < src_size; ) { c1 = src_c[src_pos++]; - if (buffer_append_c(dest, basis_64[c1 >> 2]) != 1) - return 0; + buffer_append_c(dest, basis_64[c1 >> 2]); c2 = src_pos == src_size ? 0 : src_c[src_pos]; - if (buffer_append_c(dest, basis_64[((c1 & 0x03) << 4) | - ((c2 & 0xf0) >> 4)]) != 1) - return 0; + buffer_append_c(dest, basis_64[((c1 & 0x03) << 4) | + ((c2 & 0xf0) >> 4)]); if (src_pos++ == src_size) { - if (buffer_append(dest, "==", 2) != 2) - return 0; + buffer_append(dest, "==", 2); break; } c3 = src_pos == src_size ? 0 : src_c[src_pos]; - if (buffer_append_c(dest, basis_64[((c2 & 0x0f) << 2) | - ((c3 & 0xc0) >> 6)]) != 1) - return 0; + buffer_append_c(dest, basis_64[((c2 & 0x0f) << 2) | + ((c3 & 0xc0) >> 6)]); if (src_pos++ == src_size) { - if (buffer_append_c(dest, '=') != 1) - return 0; + buffer_append_c(dest, '='); break; } - if (buffer_append_c(dest, basis_64[c3 & 0x3f]) != 1) - return 0; + buffer_append_c(dest, basis_64[c3 & 0x3f]); } - - return 1; } #define XX 127 @@ -115,7 +107,7 @@ size_t src_pos; unsigned char buf[4]; int c1, c2, c3, c4; - size_t ret, size; + size_t size; for (src_pos = 0; src_pos+3 < src_size; ) { c1 = src_c[src_pos++]; @@ -156,17 +148,7 @@ } } - ret = buffer_append(dest, buf, size); - if (ret != size) { - /* buffer full */ - if (src_pos_r != NULL) { - *src_pos_r = src_pos-4; - ret = buffer_get_used_size(dest) - (size-ret); - buffer_set_used_size(dest, ret); - } - return 0; - } - + buffer_append(dest, buf, size); if (size < 3) { /* end of base64 data */ break; @@ -176,5 +158,5 @@ if (src_pos_r != NULL) *src_pos_r = src_pos; - return 1; + return 0; } diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/base64.h --- a/src/lib/base64.h Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/base64.h Fri Oct 08 20:51:47 2004 +0300 @@ -1,14 +1,13 @@ #ifndef __BASE64_H #define __BASE64_H -/* Translates binary data into base64. The src must not point to dest buffer. - Returns 1 if all ok, 0 if dest buffer got full. */ -int base64_encode(const void *src, size_t src_size, buffer_t *dest); +/* Translates binary data into base64. The src must not point to dest buffer. */ +void base64_encode(const void *src, size_t src_size, buffer_t *dest); /* Translates base64 data into binary and appends it to dest buffer. dest may - point to same buffer as src. Returns 1 if all ok, 0 if dest buffer got full - or -1 if data is invalid. Any CR, LF characters are ignored, as well as - whitespace at beginning or end of line. + point to same buffer as src. Returns 0 if all ok, -1 if data is invalid. + Any CR, LF characters are ignored, as well as whitespace at beginning or + end of line. This function may be called multiple times for parsing the same stream. If src_pos is non-NULL, it's updated to first non-translated character in diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/buffer.c --- a/src/lib/buffer.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/buffer.c Fri Oct 08 20:51:47 2004 +0300 @@ -12,12 +12,12 @@ /* private: */ unsigned char *w_buffer; - size_t dirty, alloc, max_alloc; + size_t dirty, alloc; pool_t pool; unsigned int alloced:1; - unsigned int hard:1; + unsigned int dynamic:1; }; static void buffer_alloc(struct real_buffer *buf, size_t size) @@ -36,84 +36,47 @@ buf->alloced = TRUE; } -static int buffer_check_read(const struct real_buffer *buf, - size_t *pos, size_t *data_size) +static inline void +buffer_check_limits(struct real_buffer *buf, size_t pos, size_t data_size) { - size_t max_size; - - if (*pos >= buf->used) - return FALSE; - - max_size = buf->used - *pos; - if (*data_size > max_size) - *data_size = max_size; - return TRUE; -} + size_t new_size; -static inline int -buffer_check_limits(struct real_buffer *buf, size_t pos, size_t *data_size, - int accept_partial) -{ - size_t new_size, alloc_size; + if ((size_t)-1 - pos < data_size) { + i_panic("Buffer write out of range (%"PRIuSIZE_T + " + %"PRIuSIZE_T")", pos, data_size); + } + new_size = pos + data_size; - /* make sure we're within our limits */ - if (pos >= buf->max_alloc || - buf->max_alloc - pos < *data_size) { - if (buf->hard) { - i_panic("Buffer full (%"PRIuSIZE_T" > " - "%"PRIuSIZE_T")", pos + *data_size, - buf->max_alloc); + if (new_size > buf->alloc) { + if (!buf->dynamic) { + i_panic("Buffer full (%"PRIuSIZE_T" > %"PRIuSIZE_T")", + pos + data_size, buf->alloc); } - if (!accept_partial || pos >= buf->max_alloc) - return FALSE; - - *data_size = buf->max_alloc - pos; - } - new_size = pos + *data_size; - - /* see if we need to grow the buffer */ - if (new_size > buf->alloc) { - alloc_size = nearest_power(new_size); - if (alloc_size > buf->max_alloc) - alloc_size = buf->max_alloc; - - if (alloc_size != buf->alloc) - buffer_alloc(buf, alloc_size); + buffer_alloc(buf, nearest_power(new_size)); } if (new_size > buf->used) buf->used = new_size; - return TRUE; } -buffer_t *buffer_create_static(pool_t pool, size_t size) +buffer_t *buffer_create_static_hard(pool_t pool, size_t size) { struct real_buffer *buf; buf = p_new(pool, struct real_buffer, 1); buf->pool = pool; - buf->max_alloc = size; buffer_alloc(buf, size); return (buffer_t *)buf; } -buffer_t *buffer_create_static_hard(pool_t pool, size_t size) -{ - buffer_t *buf; - - buf = buffer_create_static(pool, size); - ((struct real_buffer *)buf)->hard = TRUE; - return buf; -} - buffer_t *buffer_create_data(pool_t pool, void *data, size_t size) { struct real_buffer *buf; buf = p_new(pool, struct real_buffer, 1); buf->pool = pool; - buf->alloc = buf->max_alloc = size; + buf->alloc = size; buf->r_buffer = buf->w_buffer = data; return (buffer_t *)buf; } @@ -124,18 +87,18 @@ buf = p_new(pool, struct real_buffer, 1); buf->pool = pool; - buf->used = buf->alloc = buf->max_alloc = size; + buf->used = buf->alloc = size; buf->r_buffer = data; return (buffer_t *)buf; } -buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size) +buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size) { struct real_buffer *buf; buf = p_new(pool, struct real_buffer, 1); buf->pool = pool; - buf->max_alloc = max_size; + buf->dynamic = TRUE; buffer_alloc(buf, init_size); return (buffer_t *)buf; } @@ -168,49 +131,44 @@ buf->used = 0; } -size_t buffer_write(buffer_t *_buf, size_t pos, - const void *data, size_t data_size) +void buffer_write(buffer_t *_buf, size_t pos, + const void *data, size_t data_size) { struct real_buffer *buf = (struct real_buffer *)_buf; - if (!buffer_check_limits(buf, pos, &data_size, TRUE)) - return 0; + buffer_check_limits(buf, pos, data_size); + memcpy(buf->w_buffer + pos, data, data_size); +} - memcpy(buf->w_buffer + pos, data, data_size); - return data_size; +void buffer_append(buffer_t *buf, const void *data, size_t data_size) +{ + buffer_write(buf, buf->used, data, data_size); } -size_t buffer_append(buffer_t *buf, const void *data, size_t data_size) +void buffer_append_c(buffer_t *buf, unsigned char chr) { - return buffer_write(buf, buf->used, data, data_size); + buffer_append(buf, &chr, 1); } -size_t buffer_append_c(buffer_t *buf, unsigned char chr) -{ - return buffer_append(buf, &chr, 1); -} - -size_t buffer_insert(buffer_t *_buf, size_t pos, - const void *data, size_t data_size) +void buffer_insert(buffer_t *_buf, size_t pos, + const void *data, size_t data_size) { struct real_buffer *buf = (struct real_buffer *)_buf; - size_t size; if (pos >= buf->used) return buffer_write(_buf, pos, data, data_size); - size = buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1); + buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1); memcpy(buf->w_buffer + pos, data, data_size); - return size; } -size_t buffer_delete(buffer_t *_buf, size_t pos, size_t size) +void buffer_delete(buffer_t *_buf, size_t pos, size_t size) { struct real_buffer *buf = (struct real_buffer *)_buf; size_t end_size; if (pos >= buf->used) - return 0; + return; end_size = buf->used - pos; if (size < end_size) { @@ -220,55 +178,50 @@ buf->w_buffer + pos + size, end_size); } else { /* delete the rest of the buffer */ - size = end_size; end_size = 0; } buffer_set_used_size(_buf, pos + end_size); - return size; } -size_t buffer_write_zero(buffer_t *_buf, size_t pos, size_t data_size) +void buffer_write_zero(buffer_t *_buf, size_t pos, size_t data_size) { struct real_buffer *buf = (struct real_buffer *)_buf; - if (!buffer_check_limits(buf, pos, &data_size, TRUE)) - return 0; - + buffer_check_limits(buf, pos, data_size); memset(buf->w_buffer + pos, 0, data_size); - return data_size; } -size_t buffer_append_zero(buffer_t *buf, size_t data_size) +void buffer_append_zero(buffer_t *buf, size_t data_size) { - return buffer_write_zero(buf, buf->used, data_size); + buffer_write_zero(buf, buf->used, data_size); } -size_t buffer_insert_zero(buffer_t *_buf, size_t pos, size_t data_size) +void buffer_insert_zero(buffer_t *_buf, size_t pos, size_t data_size) { struct real_buffer *buf = (struct real_buffer *)_buf; - size_t size; if (pos >= buf->used) return buffer_write_zero(_buf, pos, data_size); - size = buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1); + buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1); memset(buf->w_buffer + pos, 0, data_size); - return size; } -size_t buffer_copy(buffer_t *_dest, size_t dest_pos, - const buffer_t *_src, size_t src_pos, size_t copy_size) +void buffer_copy(buffer_t *_dest, size_t dest_pos, + const buffer_t *_src, size_t src_pos, size_t copy_size) { struct real_buffer *dest = (struct real_buffer *)_dest; struct real_buffer *src = (struct real_buffer *)_src; + size_t max_size; - if (!buffer_check_read(src, &src_pos, ©_size)) - return 0; + i_assert(src_pos <= src->used); - if (!buffer_check_limits(dest, dest_pos, ©_size, TRUE)) - return 0; + max_size = src->used - src_pos; + if (copy_size > max_size) + copy_size = max_size; + buffer_check_limits(dest, dest_pos, copy_size); if (src == dest) { memmove(dest->w_buffer + dest_pos, src->r_buffer + src_pos, copy_size); @@ -276,22 +229,19 @@ memcpy(dest->w_buffer + dest_pos, src->r_buffer + src_pos, copy_size); } - return copy_size; } -size_t buffer_append_buf(buffer_t *dest, const buffer_t *src, - size_t src_pos, size_t copy_size) +void buffer_append_buf(buffer_t *dest, const buffer_t *src, + size_t src_pos, size_t copy_size) { - return buffer_copy(dest, dest->used, src, src_pos, copy_size); + buffer_copy(dest, dest->used, src, src_pos, copy_size); } void *buffer_get_space_unsafe(buffer_t *_buf, size_t pos, size_t size) { struct real_buffer *buf = (struct real_buffer *)_buf; - if (!buffer_check_limits(buf, pos, &size, FALSE)) - return NULL; - + buffer_check_limits(buf, pos, size); return buf->w_buffer + pos; } @@ -327,41 +277,3 @@ return buf->alloc; } - -#ifdef BUFFER_TEST -/* gcc buffer.c -o testbuffer liblib.a -Wall -DHAVE_CONFIG_H -DBUFFER_TEST -g */ -int main(void) -{ - buffer_t *buf; - char data[12], *bufdata; - size_t bufsize; - - lib_init(); - - memset(data, '!', sizeof(data)); - bufdata = data + 1; - bufsize = sizeof(data)-2; - - buf = buffer_create_data(system_pool, bufdata, bufsize); - i_assert(buffer_write(buf, 5, "12345", 5) == 5); - i_assert(buf->used == 10); - i_assert(buffer_write(buf, 6, "12345", 5) == 4); - i_assert(buf->used == 10); - - buf = buffer_create_data(system_pool, bufdata, bufsize); - i_assert(buffer_write(buf, 0, "1234567890", 10) == 10); - i_assert(buffer_write(buf, 0, "12345678901", 11) == 10); - i_assert(buffer_append(buf, "1", 1) == 0); - i_assert(buf->used == 10); - - buf = buffer_create_data(system_pool, bufdata, bufsize); - i_assert(buffer_append(buf, "12345", 5) == 5); - i_assert(buf->used == 5); - i_assert(buffer_append(buf, "123456", 6) == 5); - i_assert(buf->used == 10); - - i_assert(data[0] == '!'); - i_assert(data[sizeof(data)-1] == '!'); - return 0; -} -#endif diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/buffer.h --- a/src/lib/buffer.h Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/buffer.h Fri Oct 08 20:51:47 2004 +0300 @@ -11,9 +11,6 @@ realloc()ed. You shouldn't rely on it being valid if you have modified buffer in any way. */ -/* Create a static sized buffer. Writes past this size will simply not - succeed. */ -buffer_t *buffer_create_static(pool_t pool, size_t size); /* Create a static sized buffer. Writes past this size will kill the program. */ buffer_t *buffer_create_static_hard(pool_t pool, size_t size); /* Create a modifyable buffer from given data. */ @@ -22,7 +19,7 @@ buffer_t *buffer_create_const_data(pool_t pool, const void *data, size_t size); /* Creates a dynamically growing buffer. Whenever write would exceed the current size it's grown. */ -buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size); +buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size); /* Free the memory used by buffer. Not needed if the memory is free'd directly from the memory pool. */ void buffer_free(buffer_t *buf); @@ -33,43 +30,41 @@ /* Reset the buffer. used size and it's contents are zeroed. */ void buffer_reset(buffer_t *buf); -/* Write data to buffer at specified position, returns number of bytes - written. */ -size_t buffer_write(buffer_t *buf, size_t pos, - const void *data, size_t data_size); -/* Append data to buffer, returns number of bytes written. */ -size_t buffer_append(buffer_t *buf, const void *data, size_t data_size); -/* Append character to buffer, returns 1 if written, 0 if not. */ -size_t buffer_append_c(buffer_t *buf, unsigned char chr); +/* Write data to buffer at specified position. */ +void buffer_write(buffer_t *buf, size_t pos, + const void *data, size_t data_size); +/* Append data to buffer. */ +void buffer_append(buffer_t *buf, const void *data, size_t data_size); +/* Append character to buffer. */ +void buffer_append_c(buffer_t *buf, unsigned char chr); -/* Insert data to buffer, returns number of bytes inserted. */ -size_t buffer_insert(buffer_t *buf, size_t pos, - const void *data, size_t data_size); -/* Delete data from buffer, returns number of bytes deleted. */ -size_t buffer_delete(buffer_t *buf, size_t pos, size_t size); +/* Insert data to buffer. */ +void buffer_insert(buffer_t *buf, size_t pos, + const void *data, size_t data_size); +/* Delete data from buffer. */ +void buffer_delete(buffer_t *buf, size_t pos, size_t size); /* Fill buffer with zero bytes. */ -size_t buffer_write_zero(buffer_t *buf, size_t pos, size_t data_size); -size_t buffer_append_zero(buffer_t *buf, size_t data_size); -size_t buffer_insert_zero(buffer_t *buf, size_t pos, size_t data_size); +void buffer_write_zero(buffer_t *buf, size_t pos, size_t data_size); +void buffer_append_zero(buffer_t *buf, size_t data_size); +void buffer_insert_zero(buffer_t *buf, size_t pos, size_t data_size); /* Copy data from buffer to another. The buffers may be same in which case it's internal copying, possibly with overlapping positions (ie. memmove() like functionality). copy_size may be set to (size_t)-1 to copy the rest of - the used data in buffer. Returns the number of bytes actually copied. */ -size_t buffer_copy(buffer_t *dest, size_t dest_pos, - const buffer_t *src, size_t src_pos, size_t copy_size); + the used data in buffer. */ +void buffer_copy(buffer_t *dest, size_t dest_pos, + const buffer_t *src, size_t src_pos, size_t copy_size); /* Append data to buffer from another. copy_size may be set to (size_t)-1 to copy the rest of the used data in buffer. */ -size_t buffer_append_buf(buffer_t *dest, const buffer_t *src, - size_t src_pos, size_t copy_size); +void buffer_append_buf(buffer_t *dest, const buffer_t *src, + size_t src_pos, size_t copy_size); -/* Returns pointer to specified position in buffer, or NULL if there's not - enough space. WARNING: The returned address may become invalid if you add - more data to buffer. */ +/* Returns pointer to specified position in buffer. WARNING: The returned + address may become invalid if you add more data to buffer. */ void *buffer_get_space_unsafe(buffer_t *buf, size_t pos, size_t size); /* Increase the buffer usage by given size, and return a pointer to beginning - of it, or NULL if there's not enough space in buffer. */ + of it. */ void *buffer_append_space_unsafe(buffer_t *buf, size_t size); /* Like buffer_get_data(), but don't return it as const. Returns NULL if the diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/hex-binary.c --- a/src/lib/hex-binary.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/hex-binary.c Fri Oct 08 20:51:47 2004 +0300 @@ -61,10 +61,9 @@ else return -1; - if (buffer_append_c(dest, value) != 1) - return 0; + buffer_append_c(dest, value); data++; } - return 1; + return 0; } diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/hex-binary.h --- a/src/lib/hex-binary.h Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/hex-binary.h Fri Oct 08 20:51:47 2004 +0300 @@ -6,8 +6,7 @@ const char *binary_to_hex_ucase(const unsigned char *data, size_t size); /* Convert hex to binary. data and dest may point to same value. - Returns TRUE if successful. Returns 1 if all ok, 0 if dest buffer got full - or -1 if data is invalid. */ + Returns 0 if all ok, -1 if data is invalid. */ int hex_to_binary(const char *data, buffer_t *dest); #endif diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/ostream-crlf.c --- a/src/lib/ostream-crlf.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/ostream-crlf.c Fri Oct 08 20:51:47 2004 +0300 @@ -117,9 +117,8 @@ t_push(); iov_buf = buffer_create_dynamic(unsafe_data_stack_pool, sizeof(struct const_iovec *) * - IOVBUF_COUNT, (size_t)-1); - diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, - IOVBUF_COUNT, (size_t)-1); + IOVBUF_COUNT); + diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, IOVBUF_COUNT); total = 0; for (vec = 0; vec < iov_count; vec++) { data = iov[vec].iov_base; @@ -224,9 +223,8 @@ t_push(); iov_buf = buffer_create_dynamic(unsafe_data_stack_pool, sizeof(struct const_iovec *) * - IOVBUF_COUNT, (size_t)-1); - diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, - IOVBUF_COUNT, (size_t)-1); + IOVBUF_COUNT); + diff_buf = buffer_create_dynamic(unsafe_data_stack_pool, IOVBUF_COUNT); total = 0; for (vec = 0; vec < iov_count; vec++) { data = iov[vec].iov_base; diff -r bd250ef1c09a -r f1e9f3ec8135 src/lib/str.c --- a/src/lib/str.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/lib/str.c Fri Oct 08 20:51:47 2004 +0300 @@ -9,7 +9,7 @@ string_t *str_new(pool_t pool, size_t initial_size) { - return buffer_create_dynamic(pool, initial_size, (size_t)-1); + return buffer_create_dynamic(pool, initial_size); } string_t *t_str_new(size_t initial_size) @@ -22,32 +22,20 @@ buffer_free(str); } -static int str_add_nul(string_t *str) +static void str_add_nul(string_t *str) { size_t len; len = str_len(str); - if (buffer_write(str, len, "", 1) != 1) { - /* no space - doesn't happen with our dynamically growing - strings though, but make sure it's \0 terminated. */ - if (len == 0) - return FALSE; - - len--; - if (buffer_write(str, len, "", 1) != 1) - i_panic("BUG in str_c()"); - } + buffer_write(str, len, "", 1); /* remove the \0 - we don't want to keep it */ buffer_set_used_size(str, len); - return TRUE; } const char *str_c(string_t *str) { - if (!str_add_nul(str)) - return ""; - + str_add_nul(str); return buffer_get_data(str, NULL); } @@ -58,9 +46,7 @@ char *str_c_modifyable(string_t *str) { - if (!str_add_nul(str)) - return NULL; - + str_add_nul(str); return buffer_get_modifyable_data(str, NULL); } diff -r bd250ef1c09a -r f1e9f3ec8135 src/pop3-login/client-authenticate.c --- a/src/pop3-login/client-authenticate.c Fri Oct 08 20:06:18 2004 +0300 +++ b/src/pop3-login/client-authenticate.c Fri Oct 08 20:51:47 2004 +0300 @@ -105,8 +105,7 @@ t_push(); - buf = buffer_create_dynamic(pool_datastack_create(), - size*2, (size_t)-1); + buf = buffer_create_dynamic(pool_datastack_create(), size*2); buffer_append(buf, "+ ", 2); base64_encode(data, size, buf); buffer_append(buf, "\r\n", 2); @@ -283,7 +282,7 @@ linelen = strlen(line); buf = buffer_create_static_hard(pool_datastack_create(), linelen); - if (base64_decode(line, linelen, NULL, buf) <= 0) { + if (base64_decode(line, linelen, NULL, buf) < 0) { /* failed */ client_auth_abort(client, "Invalid base64 data"); } else if (client->common.auth_request == NULL) { @@ -359,7 +358,7 @@ argslen = strlen(args); buf = buffer_create_static_hard(pool_datastack_create(), argslen); - if (base64_decode(args, argslen, NULL, buf) <= 0) { + if (base64_decode(args, argslen, NULL, buf) < 0) { /* failed */ client_send_line(client, "-ERR Invalid base64 data."); return TRUE; @@ -424,14 +423,13 @@ } /* APOP challenge \0 username \0 APOP response */ - apop_data = buffer_create_dynamic(pool_datastack_create(), - 128, (size_t)-1); + apop_data = buffer_create_dynamic(pool_datastack_create(), 128); buffer_append(apop_data, client->apop_challenge, strlen(client->apop_challenge)+1); buffer_append(apop_data, args, (size_t)(p-args)); buffer_append_c(apop_data, '\0'); - if (hex_to_binary(p+1, apop_data) <= 0) { + if (hex_to_binary(p+1, apop_data) < 0) { if (verbose_auth) { client_syslog(client, "APOP failed: " "Invalid characters in MD5 response");