From: Wietse Venema Date: Sat, 16 Jul 2005 05:00:00 +0000 (-0500) Subject: postfix-2.3-20050716 X-Git-Tag: v2.3-RC1~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27a0d822eab3087138ad995fe425ff0aa1299e93;p=thirdparty%2Fpostfix.git postfix-2.3-20050716 --- diff --git a/postfix/HISTORY b/postfix/HISTORY index 876998441..97dd138dc 100644 --- a/postfix/HISTORY +++ b/postfix/HISTORY @@ -10987,27 +10987,30 @@ Apologies for any names omitted. Portability: use explicitly unsigned operands when doing bit-wise shift operations on data larger than a character. -20050709-14 - - Migration of data object sizes from int->ssize_t and - unsigned->size_t for better portability to LP64 and LLP64 - systems. Simply changing everything to size_t would be - dangerous. A lot of code was written assuming signed - arithmetic; for example, it recognizes negative lengths as - an indication of integer overflow. Files: util/vbuf.[hc], - util/mymalloc.[hc], util/vstring.[hc], util/vstream.[hc], - util/timed_read.c, util/timed_write.c and functions that - override timed_read/write.c; in a later round updated pretty - much everything that contains a length of, or an offset - into, a buffer. This eliminates unnecessary conversions - back and forth between 32-bit and 64-bit integers. - -20050710-3 +20050709-15 + + Migration of data object sizes and offsets from int->ssize_t + and unsigned->size_t for better portability to LP64 and + LLP64 systems where *size_t is 64 bits wide. This change + has no effect on 32-bit systems. + + This change not only eliminated some obscure portability + bugs (see two paragraphs down), it also eliminated many + unnecessary conversions back and forth between 32-bit and + 64-bit integers, because all relevant system library functions + take *size_t arguments or return *size_t results. + + Simply changing every data object size or offset to size_t + (which is unsigned!) would be dangerous. A lot of code was + written assuming signed arithmetic and rejects negative + lengths, which can happen as the result of integer overflow. Portability: on LP64 systems, integer expressions are int, but sizeof() and pointer difference expressions are larger. - Fixed a few discrepancies with functions that expect int: - util/clean_env.c, util/argv.c, util/attr_print*.c. + The above changes fixed a few discrepancies with function + calls where *size_t was passed while the old code expected + an int: clean_env() versus argv_addn(), and code that sent + binary blobs via the TLS session cache manager protocol. 20050711 @@ -11020,6 +11023,11 @@ Apologies for any names omitted. that were incompatible with pre-DSN Postfix versions. File: cleanup/cleanup_out_recipient.c. +20050716 + + Bugfix: the smtpd_sasl_authenticated_header code did not + check if SASL was actually enabled. File: smtpd/smtpd.c. + Open problems: Look for systems with XPG basename() declared in , diff --git a/postfix/RELEASE_NOTES b/postfix/RELEASE_NOTES index a12abd678..f1ef928e0 100644 --- a/postfix/RELEASE_NOTES +++ b/postfix/RELEASE_NOTES @@ -17,6 +17,40 @@ Incompatibility with Postfix 2.1 and earlier If you upgrade from Postfix 2.1 or earlier, read RELEASE_NOTES-2.2 before proceeding. +Incompatibility with snapshot 20050715 +====================================== + +Internal interfaces have changed; this may break third-party patches +because the text of function argument and result type definitions +has changed. The type of buffer lengths and offsets were changed +from "(unsigned) int" (32 bit on 32-bit and LP64 systems) to +"(s)size_t" (64 bit on LP64 systems, 32 bit on 32-bit systems). + +Otherwise, this change makes no difference on 32-bit systems. On +LP64 systems, however, software may mis-behave 1) when Postfix is +linked with pre-compiled code that was compiled with old Postfix +interface definitions and 2) when compiling Postfix source that was +modified by a third-party patch: incorrect code may be generated +when the patch passes the wrong integer argument type in contexts +that disable automatic argument type conversions. Examples of such +contexts are formatting with printf-like arguments, and invoking +functions that write Postfix request or reply attributes across +inter-process communication channels. Unfortunately, gcc does not +report "(unsigned) int" versus "(s)size_t" format string argument +mis-matches on 32-bit systems; they can be found only on 64-bit +systems. + +Major changes with snapshot 20050715 +==================================== + +Improved portability to LP64 systems, by converting the type of +buffer lengths and offsets from "(unsigned) int" to "(s)size_t". +This change has zero effect on 32-bit systems. On LP64 platforms, +however, this change not only eliminates some obscure portability +bugs, it also eliminates unnecessary conversions between 32/64 bit +integer types, because many system library routines take "(s)size_t" +arguments or return "(s)size_t" values. + Incompatibility with snapshot 20050707 ====================================== diff --git a/postfix/makedefs b/postfix/makedefs index 5565f25d4..a01cd78a2 100644 --- a/postfix/makedefs +++ b/postfix/makedefs @@ -168,6 +168,7 @@ case "$SYSTEM.$RELEASE" in ?*) error "Don't set LD_LIBRARY_PATH";; esac case "${CC}" in + *" "*) ;; *ucb*) error "Don't use /usr/ucb/cc or ucblib";; cc*) case `which ${CC}` in *ucb*) error "Don't use /usr/ucb/cc or ucblib";; @@ -396,6 +397,9 @@ export SYSTYPE AR ARFL RANLIB SYSLIBS CC OPT DEBUG AWK OPTS # Snapshot only. CCARGS="$CCARGS -DSNAPSHOT" +# Non-production, i.e. needs thorough testing. +#CCARGS="$CCARGS -DNONPROD" + sed 's/ / /g' <buf == 0) { - reply->buf = mymalloc(DEF_DNS_REPLY_SIZE); + reply->buf = (unsigned char *) mymalloc(DEF_DNS_REPLY_SIZE); reply->buf_len = DEF_DNS_REPLY_SIZE; } @@ -228,7 +228,8 @@ static int dns_query(const char *name, int type, int flags, reply_header = (HEADER *) reply->buf; if (reply_header->tc == 0 || reply->buf_len >= MAX_DNS_REPLY_SIZE) break; - reply->buf = myrealloc(reply->buf, 2 * reply->buf_len); + reply->buf = (unsigned char *) + myrealloc((char *) reply->buf, 2 * reply->buf_len); reply->buf_len *= 2; } diff --git a/postfix/src/global/mail_version.h b/postfix/src/global/mail_version.h index fba46100c..0fd214c72 100644 --- a/postfix/src/global/mail_version.h +++ b/postfix/src/global/mail_version.h @@ -20,15 +20,24 @@ * Patches change both the patchlevel and the release date. Snapshots have no * patchlevel; they change the release date only. */ -#define MAIL_RELEASE_DATE "20050714" +#define MAIL_RELEASE_DATE "20050716" #define MAIL_VERSION_NUMBER "2.3" -#define VAR_MAIL_VERSION "mail_version" #ifdef SNAPSHOT -#define DEF_MAIL_VERSION MAIL_VERSION_NUMBER "-" MAIL_RELEASE_DATE +# define MAIL_VERSION_DATE "-" MAIL_RELEASE_DATE +#else +# define MAIL_VERSION_DATE +#endif + +#ifdef NONPROD +# define MAIL_VERSION_PROD "-nonprod" #else -#define DEF_MAIL_VERSION MAIL_VERSION_NUMBER +# define MAIL_VERSION_PROD #endif + +#define VAR_MAIL_VERSION "mail_version" +#define DEF_MAIL_VERSION MAIL_VERSION_NUMBER MAIL_VERSION_DATE MAIL_VERSION_PROD + extern char *var_mail_version; /* diff --git a/postfix/src/global/pipe_command.c b/postfix/src/global/pipe_command.c index d3319ec30..245e492dc 100644 --- a/postfix/src/global/pipe_command.c +++ b/postfix/src/global/pipe_command.c @@ -268,7 +268,9 @@ static void get_pipe_args(struct pipe_args * args, va_list ap) /* pipe_command_write - write to command with time limit */ -static ssize_t pipe_command_write(int fd, void *buf, ssize_t len) +static ssize_t pipe_command_write(int fd, void *buf, size_t len, + int unused_timeout, + void *unused_context) { int maxtime = (pipe_command_timeout == 0) ? pipe_command_maxtime : 0; char *myname = "pipe_command_write"; @@ -289,7 +291,9 @@ static ssize_t pipe_command_write(int fd, void *buf, ssize_t len) /* pipe_command_read - read from command with time limit */ -static ssize_t pipe_command_read(int fd, void *buf, ssize_t len) +static ssize_t pipe_command_read(int fd, void *buf, ssize_t len, + int unused_timeout, + void *unused_context) { int maxtime = (pipe_command_timeout == 0) ? pipe_command_maxtime : 0; char *myname = "pipe_command_read"; diff --git a/postfix/src/global/record.c b/postfix/src/global/record.c index 2e63278ef..15cc1bd60 100644 --- a/postfix/src/global/record.c +++ b/postfix/src/global/record.c @@ -132,7 +132,7 @@ int rec_put_type(VSTREAM *stream, int type, long offset) int rec_put(VSTREAM *stream, int type, const char *data, ssize_t len) { ssize_t len_rest; - ssize_t len_byte; + int len_byte; if (type < 0 || type > 255) msg_panic("rec_put: bad record type %d", type); @@ -234,7 +234,7 @@ int rec_get(VSTREAM *stream, VSTRING *buf, ssize_t maxsize) VSTRING_TERMINATE(buf); if (msg_verbose > 2) msg_info("%s: type %c len %ld data %.10s", myname, - type, (unsigned long) len, vstring_str(buf)); + type, (long) len, vstring_str(buf)); return (type); } diff --git a/postfix/src/global/smtp_stream.c b/postfix/src/global/smtp_stream.c index dbaf48c6c..d836e6736 100644 --- a/postfix/src/global/smtp_stream.c +++ b/postfix/src/global/smtp_stream.c @@ -319,7 +319,7 @@ int smtp_get(VSTRING *vp, VSTREAM *stream, ssize_t bound) void smtp_fputs(const char *cp, ssize_t todo, VSTREAM *stream) { - size_t err; + ssize_t err; if (todo < 0) msg_panic("smtp_fputs: negative todo %ld", (long) todo); @@ -346,7 +346,7 @@ void smtp_fputs(const char *cp, ssize_t todo, VSTREAM *stream) void smtp_fwrite(const char *cp, ssize_t todo, VSTREAM *stream) { - size_t err; + ssize_t err; if (todo < 0) msg_panic("smtp_fwrite: negative todo %ld", (long) todo); diff --git a/postfix/src/lmtp/lmtp_chat.c b/postfix/src/lmtp/lmtp_chat.c index e99107c2a..608b8a8f3 100644 --- a/postfix/src/lmtp/lmtp_chat.c +++ b/postfix/src/lmtp/lmtp_chat.c @@ -286,11 +286,11 @@ LMTP_RESP *lmtp_chat_resp(LMTP_STATE *state) /* print_line - line_wrap callback */ -static void print_line(const char *str, ssize_t len, ssize_t indent, char *context) +static void print_line(const char *str, int len, int indent, char *context) { VSTREAM *notice = (VSTREAM *) context; - post_mail_fprintf(notice, " %*s%.*s", (int) indent, "", (int) len, str); + post_mail_fprintf(notice, " %*s%.*s", indent, "", len, str); } /* lmtp_chat_notify - notify postmaster */ diff --git a/postfix/src/lmtp/lmtp_sasl_glue.c b/postfix/src/lmtp/lmtp_sasl_glue.c index 0ca789a27..371bfc6fe 100644 --- a/postfix/src/lmtp/lmtp_sasl_glue.c +++ b/postfix/src/lmtp/lmtp_sasl_glue.c @@ -124,11 +124,6 @@ static NAME_MASK lmtp_sasl_sec_mask[] = { 0, }; - /* - * Silly little macros. - */ -#define STR(x) vstring_str(x) - /* * Macros to handle API differences between SASLv1 and SASLv2. Specifics: * diff --git a/postfix/src/smtp/smtp.h b/postfix/src/smtp/smtp.h index 2d3f4f617..d924ce343 100644 --- a/postfix/src/smtp/smtp.h +++ b/postfix/src/smtp/smtp.h @@ -51,7 +51,7 @@ typedef struct SMTP_STATE { DELIVER_REQUEST *request; /* envelope info, offsets */ struct SMTP_SESSION *session; /* network connection */ int status; /* delivery status */ - int space_left; /* output length control */ + ssize_t space_left; /* output length control */ /* * Connection cache support. The (nexthop_lookup_mx, nexthop_domain, diff --git a/postfix/src/smtp/smtp_chat.c b/postfix/src/smtp/smtp_chat.c index 4e9b6f3eb..7f27fc20f 100644 --- a/postfix/src/smtp/smtp_chat.c +++ b/postfix/src/smtp/smtp_chat.c @@ -306,11 +306,11 @@ SMTP_RESP *smtp_chat_resp(SMTP_SESSION *session) /* print_line - line_wrap callback */ -static void print_line(const char *str, ssize_t len, ssize_t indent, char *context) +static void print_line(const char *str, int len, int indent, char *context) { VSTREAM *notice = (VSTREAM *) context; - post_mail_fprintf(notice, " %*s%.*s", (int) indent, "", (int) len, str); + post_mail_fprintf(notice, " %*s%.*s", indent, "", len, str); } /* smtp_chat_notify - notify postmaster */ diff --git a/postfix/src/smtp/smtp_sasl_glue.c b/postfix/src/smtp/smtp_sasl_glue.c index fe437fb0e..ef6c4cb6e 100644 --- a/postfix/src/smtp/smtp_sasl_glue.c +++ b/postfix/src/smtp/smtp_sasl_glue.c @@ -139,11 +139,6 @@ static NAME_MASK smtp_sasl_sec_mask[] = { 0, }; - /* - * Silly little macros. - */ -#define STR(x) vstring_str(x) - /* * Macros to handle API differences between SASLv1 and SASLv2. Specifics: * diff --git a/postfix/src/smtpd/smtpd.c b/postfix/src/smtpd/smtpd.c index 7be9340df..62636081b 100644 --- a/postfix/src/smtpd/smtpd.c +++ b/postfix/src/smtpd/smtpd.c @@ -2167,7 +2167,7 @@ static int data_cmd(SMTPD_STATE *state, int argc, SMTPD_TOKEN *unused_argv) } #endif #ifdef USE_SASL_AUTH - if (var_smtpd_sasl_auth_hdr && state->sasl_username) { + if (var_smtpd_sasl_enable && var_smtpd_sasl_auth_hdr && state->sasl_username) { username = VSTRING_STRDUP(state->sasl_username); comment_sanitize(username); out_fprintf(out_stream, REC_TYPE_NORM, diff --git a/postfix/src/smtpd/smtpd_chat.c b/postfix/src/smtpd/smtpd_chat.c index 394e52b16..2962b1efb 100644 --- a/postfix/src/smtpd/smtpd_chat.c +++ b/postfix/src/smtpd/smtpd_chat.c @@ -183,11 +183,11 @@ void smtpd_chat_reply(SMTPD_STATE *state, char *format,...) /* print_line - line_wrap callback */ -static void print_line(const char *str, ssize_t len, ssize_t indent, char *context) +static void print_line(const char *str, int len, int indent, char *context) { VSTREAM *notice = (VSTREAM *) context; - post_mail_fprintf(notice, " %*s%.*s", (int) indent, "", (int) len, str); + post_mail_fprintf(notice, " %*s%.*s", indent, "", len, str); } /* smtpd_chat_notify - notify postmaster */ diff --git a/postfix/src/smtpd/smtpd_check.c b/postfix/src/smtpd/smtpd_check.c index a56c4cb76..b2b2065ed 100644 --- a/postfix/src/smtpd/smtpd_check.c +++ b/postfix/src/smtpd/smtpd_check.c @@ -1119,12 +1119,12 @@ static int reject_unknown_hostname(SMTPD_STATE *state, char *name, RR_ADDR_TYPES, T_MX, 0); if (dns_status == DNS_NOTFOUND) return (smtpd_check_reject(state, MAIL_ERROR_POLICY, - var_unk_name_code, "4.1.0", + var_unk_name_code, "4.7.1", "<%s>: %s rejected: Host not found", reply_name, reply_class)); else if (dns_status != DNS_OK) DEFER_IF_PERMIT2(state, MAIL_ERROR_POLICY, - 450, "4.1.0", + 450, "4.7.1", "<%s>: %s rejected: Host not found", reply_name, reply_class); return (SMTPD_CHECK_DUNNO); diff --git a/postfix/src/smtpstone/qmqp-source.c b/postfix/src/smtpstone/qmqp-source.c index ec0c457d6..628ebd2a7 100644 --- a/postfix/src/smtpstone/qmqp-source.c +++ b/postfix/src/smtpstone/qmqp-source.c @@ -372,7 +372,7 @@ static void send_data(SESSION *session) STR(message_buffer), LEN(message_buffer), STR(sender_buffer), LEN(sender_buffer), STR(recipient_buffer), LEN(recipient_buffer), - (ssize_t) 0); + (char *) 0); netstring_fflush(session->stream); /* diff --git a/postfix/src/tls/tls_scache.c b/postfix/src/tls/tls_scache.c index d141967ee..bcd2cc03f 100644 --- a/postfix/src/tls/tls_scache.c +++ b/postfix/src/tls/tls_scache.c @@ -24,7 +24,7 @@ /* TLS_SCACHE *cache; /* const char *cache_id; /* const char *session; -/* int session_len; +/* ssize_t session_len; /* /* int tls_scache_sequence(cache, first_next, out_cache_id, /* VSTRING *out_session) diff --git a/postfix/src/trivial-rewrite/resolve.c b/postfix/src/trivial-rewrite/resolve.c index f12583884..3d6cd7627 100644 --- a/postfix/src/trivial-rewrite/resolve.c +++ b/postfix/src/trivial-rewrite/resolve.c @@ -147,8 +147,8 @@ static void resolve_addr(RES_CONTEXT *rp, char *addr, const char *blame = 0; const char *rcpt_domain; ssize_t addr_len; - int loop_count; - int loop_max; + ssize_t loop_count; + ssize_t loop_max; char *local; char *oper; char *junk; @@ -233,8 +233,8 @@ static void resolve_addr(RES_CONTEXT *rp, char *addr, * disrupt the operation of an MTA. */ if (loop_count > loop_max) { - msg_warn("resolve_addr: <%s>: giving up after %d iterations", - addr, loop_count); + msg_warn("resolve_addr: <%s>: giving up after %ld iterations", + addr, (long) loop_count); break; } diff --git a/postfix/src/util/environ.c b/postfix/src/util/environ.c index 294ca199b..4b6c59e30 100644 --- a/postfix/src/util/environ.c +++ b/postfix/src/util/environ.c @@ -34,7 +34,7 @@ static ssize_t namelength(const char *name) /* findenv - given name, locate name=value */ -static char **findenv(const char *name, int len) +static char **findenv(const char *name, ssize_t len) { char **envp; @@ -50,7 +50,7 @@ static char **findenv(const char *name, int len) char *getenv(const char *name) { - int len = namelength(name); + ssize_t len = namelength(name); char **envp = findenv(name, len); return (envp ? *envp + len + 1 : 0); @@ -85,7 +85,7 @@ int setenv(const char *name, const char *value, int clobber) { char *destination; char **envp; - int l_name; /* length of name part */ + ssize_t l_name; /* length of name part */ unsigned int l_nameval; /* length of name=value */ /* Permit name= and =value. */ diff --git a/postfix/src/util/inet_addr_host.c b/postfix/src/util/inet_addr_host.c index f330e5b5a..aab2e97a7 100644 --- a/postfix/src/util/inet_addr_host.c +++ b/postfix/src/util/inet_addr_host.c @@ -149,20 +149,19 @@ int main(int argc, char **argv) proto_info = inet_proto_init(argv[0], argv[1]); argv += 1; - inet_addr_list_init(&list); - while (--argc && *++argv) { + inet_addr_list_init(&list); if (inet_addr_host(&list, *argv) == 0) msg_fatal("not found: %s", *argv); for (sa = list.addrs; sa < list.addrs + list.used; sa++) { SOCKADDR_TO_HOSTADDR(SOCK_ADDR_PTR(sa), SOCK_ADDR_LEN(sa), &hostaddr, (MAI_SERVPORT_STR *) 0, 0); - vstream_printf("%s\n", hostaddr.buf); + vstream_printf("%s\t%s\n", *argv, hostaddr.buf); } vstream_fflush(VSTREAM_OUT); + inet_addr_list_free(&list); } - inet_addr_list_free(&list); return (0); } diff --git a/postfix/src/util/line_wrap.c b/postfix/src/util/line_wrap.c index 38c5558cf..50d172cab 100644 --- a/postfix/src/util/line_wrap.c +++ b/postfix/src/util/line_wrap.c @@ -73,16 +73,16 @@ void print(const char *str, int len, int indent, char *context) /* line_wrap - wrap long lines upon output */ -void line_wrap(const char *str, ssize_t len, ssize_t indent, LINE_WRAP_FN output_fn, +void line_wrap(const char *str, int len, int indent, LINE_WRAP_FN output_fn, char *context) { const char *start_line; const char *word; const char *next_word; const char *next_space; - ssize_t line_len; - ssize_t curr_len; - ssize_t curr_indent; + int line_len; + int curr_len; + int curr_indent; if (indent < 0) { curr_indent = -indent; diff --git a/postfix/src/util/line_wrap.h b/postfix/src/util/line_wrap.h index d1b0c18ea..b901c1f3d 100644 --- a/postfix/src/util/line_wrap.h +++ b/postfix/src/util/line_wrap.h @@ -14,8 +14,8 @@ /* * External interface. */ -typedef void (*LINE_WRAP_FN) (const char *, ssize_t, ssize_t, char *); -extern void line_wrap(const char *, ssize_t, ssize_t, LINE_WRAP_FN, char *); +typedef void (*LINE_WRAP_FN) (const char *, int, int, char *); +extern void line_wrap(const char *, int, int, LINE_WRAP_FN, char *); /* LICENSE /* .ad diff --git a/postfix/src/util/netstring.c b/postfix/src/util/netstring.c index 82b54941c..7dfee0a34 100644 --- a/postfix/src/util/netstring.c +++ b/postfix/src/util/netstring.c @@ -22,7 +22,7 @@ /* void netstring_put(stream, data, len) /* VSTREAM *stream; /* const char *data; -/* int ssize_t; +/* ssize_t len; /* /* void netstring_put_multi(stream, data, len, data, len, ..., 0) /* VSTREAM *stream; @@ -39,7 +39,7 @@ /* VSTRING *netstring_memcpy(buf, data, len) /* VSTRING *buf; /* const char *data; -/* int ssize_t; +/* ssize_t len; /* /* VSTRING *netstring_memcat(buf, data, len) /* VSTRING *buf; diff --git a/postfix/src/util/vstring.h b/postfix/src/util/vstring.h index 3c792005e..e031bbcf8 100644 --- a/postfix/src/util/vstring.h +++ b/postfix/src/util/vstring.h @@ -58,24 +58,30 @@ extern VSTRING *vstring_import(char *); #define vstring_str(vp) ((char *) (vp)->vbuf.data) #define VSTRING_LEN(vp) ((ssize_t) ((vp)->vbuf.ptr - (vp)->vbuf.data)) #define vstring_end(vp) ((char *) (vp)->vbuf.ptr) -#define VSTRING_TERMINATE(vp) { if ((vp)->vbuf.cnt <= 0) \ +#define VSTRING_TERMINATE(vp) do { \ + if ((vp)->vbuf.cnt <= 0) \ VSTRING_SPACE((vp),1); \ - *(vp)->vbuf.ptr = 0; } -#define VSTRING_RESET(vp) { (vp)->vbuf.ptr = (vp)->vbuf.data; \ - (vp)->vbuf.cnt = (vp)->vbuf.len; } + *(vp)->vbuf.ptr = 0; \ + } while (0) +#define VSTRING_RESET(vp) do { \ + (vp)->vbuf.ptr = (vp)->vbuf.data; \ + (vp)->vbuf.cnt = (vp)->vbuf.len; \ + } while (0) #define VSTRING_ADDCH(vp, ch) VBUF_PUT(&(vp)->vbuf, ch) -#define VSTRING_SKIP(vp) { while ((vp)->vbuf.cnt > 0 && *(vp)->vbuf.ptr) \ - (vp)->vbuf.ptr++, (vp)->vbuf.cnt--; } +#define VSTRING_SKIP(vp) do { \ + while ((vp)->vbuf.cnt > 0 && *(vp)->vbuf.ptr) \ + (vp)->vbuf.ptr++, (vp)->vbuf.cnt--; \ + } while (0) #define vstring_avail(vp) ((vp)->vbuf.cnt) /* * The following macro is not part of the public interface, because it can * really screw up a buffer by positioning past allocated memory. */ -#define VSTRING_AT_OFFSET(vp, offset) { \ +#define VSTRING_AT_OFFSET(vp, offset) do { \ (vp)->vbuf.ptr = (vp)->vbuf.data + (offset); \ (vp)->vbuf.cnt = (vp)->vbuf.len - (offset); \ - } + } while (0) extern VSTRING *vstring_vsprintf(VSTRING *, const char *, va_list); extern VSTRING *vstring_vsprintf_append(VSTRING *, const char *, va_list); diff --git a/postfix/src/util/vstring_vstream.c b/postfix/src/util/vstring_vstream.c index 7c7842733..36c913472 100644 --- a/postfix/src/util/vstring_vstream.c +++ b/postfix/src/util/vstring_vstream.c @@ -21,17 +21,17 @@ /* int vstring_get_bound(vp, fp, bound) /* VSTRING *vp; /* VSTREAM *fp; -/* int bound; +/* ssize_t bound; /* /* int vstring_get_nonl_bound(vp, fp, bound) /* VSTRING *vp; /* VSTREAM *fp; -/* int bound; +/* ssize_t bound; /* /* int vstring_get_null_bound(vp, fp, bound) /* VSTRING *vp; /* VSTREAM *fp; -/* int bound; +/* ssize_t bound; /* DESCRIPTION /* The routines in this module each read one newline or null-terminated /* string from an input stream. In all cases the result is either the @@ -126,12 +126,12 @@ int vstring_get_null(VSTRING *vp, VSTREAM *fp) /* vstring_get_bound - read line from file, keep newline, up to bound */ -int vstring_get_bound(VSTRING *vp, VSTREAM *fp, int bound) +int vstring_get_bound(VSTRING *vp, VSTREAM *fp, ssize_t bound) { int c; if (bound <= 0) - msg_panic("vstring_get_bound: invalid bound %d", bound); + msg_panic("vstring_get_bound: invalid bound %ld", (long) bound); VSTRING_RESET(vp); while (bound-- > 0 && (c = VSTREAM_GETC(fp)) != VSTREAM_EOF) { @@ -145,12 +145,12 @@ int vstring_get_bound(VSTRING *vp, VSTREAM *fp, int bound) /* vstring_get_nonl_bound - read line from file, strip newline, up to bound */ -int vstring_get_nonl_bound(VSTRING *vp, VSTREAM *fp, int bound) +int vstring_get_nonl_bound(VSTRING *vp, VSTREAM *fp, ssize_t bound) { int c; if (bound <= 0) - msg_panic("vstring_get_nonl_bound: invalid bound %d", bound); + msg_panic("vstring_get_nonl_bound: invalid bound %ld", (long) bound); VSTRING_RESET(vp); while (bound-- > 0 && (c = VSTREAM_GETC(fp)) != VSTREAM_EOF && c != '\n') @@ -161,12 +161,12 @@ int vstring_get_nonl_bound(VSTRING *vp, VSTREAM *fp, int bound) /* vstring_get_null_bound - read null-terminated string from file */ -int vstring_get_null_bound(VSTRING *vp, VSTREAM *fp, int bound) +int vstring_get_null_bound(VSTRING *vp, VSTREAM *fp, ssize_t bound) { int c; if (bound <= 0) - msg_panic("vstring_get_nonl_bound: invalid bound %d", bound); + msg_panic("vstring_get_nonl_bound: invalid bound %ld", (long) bound); VSTRING_RESET(vp); while (bound-- > 0 && (c = VSTREAM_GETC(fp)) != VSTREAM_EOF && c != 0) diff --git a/postfix/src/util/vstring_vstream.h b/postfix/src/util/vstring_vstream.h index 68bd8106d..9bd9d7127 100644 --- a/postfix/src/util/vstring_vstream.h +++ b/postfix/src/util/vstring_vstream.h @@ -22,9 +22,9 @@ extern int vstring_get(VSTRING *, VSTREAM *); extern int vstring_get_nonl(VSTRING *, VSTREAM *); extern int vstring_get_null(VSTRING *, VSTREAM *); -extern int vstring_get_bound(VSTRING *, VSTREAM *, int); -extern int vstring_get_nonl_bound(VSTRING *, VSTREAM *, int); -extern int vstring_get_null_bound(VSTRING *, VSTREAM *, int); +extern int vstring_get_bound(VSTRING *, VSTREAM *, ssize_t); +extern int vstring_get_nonl_bound(VSTRING *, VSTREAM *, ssize_t); +extern int vstring_get_null_bound(VSTRING *, VSTREAM *, ssize_t); /* * Backwards compatibility for code that still uses the vstring_fgets() diff --git a/postfix/src/util/write_buf.c b/postfix/src/util/write_buf.c index 2bce6c972..954436564 100644 --- a/postfix/src/util/write_buf.c +++ b/postfix/src/util/write_buf.c @@ -56,6 +56,7 @@ ssize_t write_buf(int fd, const char *buf, ssize_t len, int timeout) { + const char *start = buf; ssize_t count; while (len > 0) { @@ -71,5 +72,5 @@ ssize_t write_buf(int fd, const char *buf, ssize_t len, int timeout) buf += count; len -= count; } - return (len); + return (buf - start); }