From 38d3295b385fc78339eec2316789ed13a0c49e82 Mon Sep 17 00:00:00 2001 From: Wietse Venema Date: Fri, 13 Jul 2012 00:00:00 -0500 Subject: [PATCH] postfix-2.10-20120713 --- postfix/HISTORY | 17 +++++++++ postfix/makedefs | 2 +- postfix/src/dns/dns_sa_to_rr.ref | 2 +- postfix/src/global/mail_version.h | 2 +- postfix/src/local/biff_notify.c | 10 ++++-- postfix/src/util/binhash.c | 2 +- postfix/src/util/htable.c | 2 +- postfix/src/util/myaddrinfo.ref | 4 +-- postfix/src/util/vstream.c | 59 +++++++++++++++++-------------- postfix/src/util/vstream_tweak.c | 8 ++--- 10 files changed, 67 insertions(+), 41 deletions(-) diff --git a/postfix/HISTORY b/postfix/HISTORY index 9426fafe0..3058d8fb6 100644 --- a/postfix/HISTORY +++ b/postfix/HISTORY @@ -17877,3 +17877,20 @@ Apologies for any names omitted. 20120629 Workaround: "sendmail -bl" emulation. File: sendmail/sendmail.c. + +20120630 + + Cleanup: sub-optimal hash performance on systems where the + "char" type is signed. Files: util/htable.c, util/binhash.c. + +20120702 + + Bugfix (introduced: 19990127): the BIFF client leaked an + unprivileged UDP socket. Fix by Jaroslav Skarvada. File: + local/biff_notify.c. + +20120713 + + Bugfix (introduced: 20120527-8): infrastructure to specify + a smaller-than-default VSTREAM buffer, without the complex + run-time checks. File: util/vstream.c, vstream_tweak.c. diff --git a/postfix/makedefs b/postfix/makedefs index 92a9717c3..d9149b4e5 100644 --- a/postfix/makedefs +++ b/postfix/makedefs @@ -367,7 +367,7 @@ EOF esac for name in nsl resolv do - for lib in /usr/lib64 /lib64 /usr/lib /lib + for lib in /usr/lib64 /lib64 /usr/lib /usr/lib/* /lib /lib/* do test -e $lib/lib$name.a -o -e $lib/lib$name.so && { SYSLIBS="$SYSLIBS -l$name" diff --git a/postfix/src/dns/dns_sa_to_rr.ref b/postfix/src/dns/dns_sa_to_rr.ref index 86c022d56..0b67b74e2 100644 --- a/postfix/src/dns/dns_sa_to_rr.ref +++ b/postfix/src/dns/dns_sa_to_rr.ref @@ -1,2 +1,2 @@ -spike.porcupine.org -> 168.100.189.2 spike.porcupine.org -> 2604:8d00:189::2 +spike.porcupine.org -> 168.100.189.2 diff --git a/postfix/src/global/mail_version.h b/postfix/src/global/mail_version.h index 4479ab0e4..965b8a07f 100644 --- a/postfix/src/global/mail_version.h +++ b/postfix/src/global/mail_version.h @@ -20,7 +20,7 @@ * Patches change both the patchlevel and the release date. Snapshots have no * patchlevel; they change the release date only. */ -#define MAIL_RELEASE_DATE "20120630" +#define MAIL_RELEASE_DATE "20120713" #define MAIL_VERSION_NUMBER "2.10" #ifdef SNAPSHOT diff --git a/postfix/src/local/biff_notify.c b/postfix/src/local/biff_notify.c index b189ad4b2..ca7dc1645 100644 --- a/postfix/src/local/biff_notify.c +++ b/postfix/src/local/biff_notify.c @@ -43,6 +43,7 @@ /* Utility library. */ #include +#include /* Application-specific. */ @@ -81,9 +82,12 @@ void biff_notify(const char *text, ssize_t len) /* * Open a socket, or re-use an existing one. */ - if (sock < 0 && (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - msg_warn("socket: %m"); - return; + if (sock < 0) { + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + msg_warn("socket: %m"); + return; + } + close_on_exec(sock, CLOSE_ON_EXEC); } /* diff --git a/postfix/src/util/binhash.c b/postfix/src/util/binhash.c index b877f77ee..84ca87c75 100644 --- a/postfix/src/util/binhash.c +++ b/postfix/src/util/binhash.c @@ -134,7 +134,7 @@ static unsigned binhash_hash(const char *key, int len, unsigned size) */ while (len-- > 0) { - h = (h << 4U) + *key++; + h = (h << 4U) + *(unsigned const char *) key++; if ((g = (h & 0xf0000000)) != 0) { h ^= (g >> 24U); h ^= g; diff --git a/postfix/src/util/htable.c b/postfix/src/util/htable.c index 3fc981a35..009e0fcdf 100644 --- a/postfix/src/util/htable.c +++ b/postfix/src/util/htable.c @@ -138,7 +138,7 @@ static unsigned htable_hash(const char *s, unsigned size) */ while (*s) { - h = (h << 4U) + *s++; + h = (h << 4U) + *(unsigned const char *) s++; if ((g = (h & 0xf0000000)) != 0) { h ^= (g >> 24U); h ^= g; diff --git a/postfix/src/util/myaddrinfo.ref b/postfix/src/util/myaddrinfo.ref index 360228a10..f0da580cb 100644 --- a/postfix/src/util/myaddrinfo.ref +++ b/postfix/src/util/myaddrinfo.ref @@ -1,8 +1,8 @@ ./myaddrinfo: === hostname belly.porcupine.org === -./myaddrinfo: belly.porcupine.org -> family=2 sock=1 proto=6 168.100.189.6 -./myaddrinfo: 168.100.189.6 -> belly.porcupine.org ./myaddrinfo: belly.porcupine.org -> family=28 sock=1 proto=6 2604:8d00:189::6 ./myaddrinfo: 2604:8d00:189::6 -> belly.porcupine.org +./myaddrinfo: belly.porcupine.org -> family=2 sock=1 proto=6 168.100.189.6 +./myaddrinfo: 168.100.189.6 -> belly.porcupine.org ./myaddrinfo: === host address 168.100.189.2 === ./myaddrinfo: 168.100.189.2 -> family=2 sock=1 proto=6 168.100.189.2 ./myaddrinfo: 168.100.189.2 -> spike.porcupine.org diff --git a/postfix/src/util/vstream.c b/postfix/src/util/vstream.c index 38eb02246..7a7b7dbcb 100644 --- a/postfix/src/util/vstream.c +++ b/postfix/src/util/vstream.c @@ -324,17 +324,18 @@ /* This involves allocation of additional memory that normally isn't /* used. /* .IP "VSTREAM_CTL_BUFSIZE (ssize_t)" -/* Specify a non-default buffer size, or zero to implement -/* a no-op. Requests to resize a fixed-size buffer (stderr) -/* are not allowed. +/* Specify a non-default write buffer size, or zero to implement +/* a no-op. Requests to shrink an existing buffer size are +/* silently ignored. To get a buffer size smaller than +/* VSTREAM_BUFSIZE, make the VSTREAM_CTL_BUFSIZE before the +/* stream has been used. Requests to change a fixed-size buffer +/* (e.g., stderr) are not allowed. /* /* NOTE: the VSTREAM_CTL_BUFSIZE request specifies intent, not /* reality. Actual buffer sizes are not updated immediately. -/* Instead, a write buffer size will be updated when writing -/* to a stream for the first time, or when writing to a full -/* buffer, and a read buffer size will be updated when reading -/* from a stream for the first time, or when reading from an -/* empty buffer. +/* Instead, an existing write buffer will be resized when it +/* is full, and an existing read buffer will be resized when +/* the buffer is filled. /* /* NOTE: the vstream_*printf() routines may silently expand a /* buffer, so that the result of some %letter specifiers can @@ -503,13 +504,13 @@ VSTREAM vstream_fstd[] = { 0, 0, 0, 0, /* buffer */ vstream_buf_get_ready, vstream_buf_put_ready, vstream_buf_space, }, STDIN_FILENO, (VSTREAM_FN) timed_read, (VSTREAM_FN) timed_write, - VSTREAM_BUFSIZE,}, + 0,}, {{ 0, /* flags */ 0, 0, 0, 0, /* buffer */ vstream_buf_get_ready, vstream_buf_put_ready, vstream_buf_space, }, STDOUT_FILENO, (VSTREAM_FN) timed_read, (VSTREAM_FN) timed_write, - VSTREAM_BUFSIZE,}, + 0,}, {{ VBUF_FLAG_FIXED | VSTREAM_FLAG_WRITE, vstream_fstd_buf, VSTREAM_BUFSIZE, VSTREAM_BUFSIZE, vstream_fstd_buf, @@ -626,17 +627,10 @@ static void vstream_buf_alloc(VBUF *bp, ssize_t len) ssize_t used = bp->ptr - bp->data; const char *myname = "vstream_buf_alloc"; - /* - * Don't shrink a non-empty read buffer, or a non-flushed write buffer. - */ - if (len <= 0) - msg_panic("%s: bad buffer length: %ld", myname, (long) len); - if (len < bp->len - && (((bp->flags & VSTREAM_FLAG_READ) && bp->cnt != 0) - || ((bp->flags & VSTREAM_FLAG_WRITE) && bp->cnt != bp->len))) - msg_panic("%s: attempt to shrink non-empty buffer", myname); + if (len < bp->len) + msg_panic("%s: attempt to shrink buffer", myname); if (bp->flags & VSTREAM_FLAG_FIXED) - msg_panic("%s: attempt to resize fixed-length buffer", myname); + msg_panic("%s: unable to extend fixed-size buffer", myname); /* * Late buffer allocation allows the user to override the default policy. @@ -853,8 +847,12 @@ static int vstream_buf_get_ready(VBUF *bp) * If this is the first GET operation, allocate a buffer. Late buffer * allocation gives the application a chance to override the default * buffering policy. + * + * XXX Tricky code to set the preferred buffer size as late as possible. */ - if (bp->len != stream->req_bufsize) + if (stream->req_bufsize == 0) + stream->req_bufsize = VSTREAM_BUFSIZE; + if (bp->len < stream->req_bufsize) vstream_buf_alloc(bp, stream->req_bufsize); /* @@ -961,15 +959,17 @@ static int vstream_buf_put_ready(VBUF *bp) * stream or if the buffer is smaller than the requested size, allocate a * new buffer; obviously there is no data to be flushed yet. Otherwise, * flush the buffer. + * + * XXX Tricky code to set the preferred buffer size as late as possible. */ + if (stream->req_bufsize == 0) + stream->req_bufsize = VSTREAM_BUFSIZE; if (bp->len < stream->req_bufsize) { vstream_buf_alloc(bp, stream->req_bufsize); } else if (bp->cnt <= 0) { if (VSTREAM_FFLUSH_SOME(stream)) return (VSTREAM_EOF); } - if (bp->len > stream->req_bufsize) - vstream_buf_alloc(bp, stream->req_bufsize); return (0); } @@ -1014,10 +1014,14 @@ static int vstream_buf_space(VBUF *bp, ssize_t want) * VSTREAM_BUFSIZE bytes and resize the buffer to a multiple of * VSTREAM_BUFSIZE. We flush multiples of VSTREAM_BUFSIZE in an attempt * to keep file updates block-aligned for better performance. + * + * XXX Tricky code to set the preferred buffer size as late as possible. */ #define VSTREAM_TRUNCATE(count, base) (((count) / (base)) * (base)) #define VSTREAM_ROUNDUP(count, base) VSTREAM_TRUNCATE(count + base - 1, base) + if (stream->req_bufsize == 0) + stream->req_bufsize = VSTREAM_BUFSIZE; if (want > bp->cnt) { if ((used = bp->len - bp->cnt) > stream->req_bufsize) if (vstream_fflush_some(stream, VSTREAM_TRUNCATE(used, stream->req_bufsize))) @@ -1231,7 +1235,7 @@ VSTREAM *vstream_fdopen(int fd, int flags) stream->jbuf = 0; stream->iotime.tv_sec = stream->iotime.tv_usec = 0; stream->time_limit.tv_sec = stream->time_limit.tv_usec = 0; - stream->req_bufsize = VSTREAM_BUFSIZE; + stream->req_bufsize = 0; return (stream); } @@ -1482,7 +1486,8 @@ void vstream_control(VSTREAM *stream, int name,...) if (req_bufsize < 0 || req_bufsize > INT_MAX) msg_panic("unreasonable VSTREAM_CTL_BUFSIZE request: %ld", (long) req_bufsize); - if (req_bufsize > 0 && stream != VSTREAM_ERR) + if (stream != VSTREAM_ERR + && req_bufsize > stream->req_bufsize) stream->req_bufsize = req_bufsize; break; @@ -1625,9 +1630,9 @@ int main(int argc, char **argv) * Test buffer expansion and shrinking. Formatted print may silently * expand the write buffer and cause multiple bytes to be written. */ - copy_line(1); /* one-byte read/write */ + copy_line(1); /* one-byte read/write */ copy_line(2); /* two-byte read/write */ - copy_line(1); /* one-byte read/write */ + copy_line(1); /* two-byte read/write */ printf_number(); /* multi-byte write */ exit(0); } diff --git a/postfix/src/util/vstream_tweak.c b/postfix/src/util/vstream_tweak.c index 166ffc0c8..5c528376a 100644 --- a/postfix/src/util/vstream_tweak.c +++ b/postfix/src/util/vstream_tweak.c @@ -116,12 +116,12 @@ int vstream_tweak_tcp(VSTREAM *fp) /* * Fix for recent Postfix versions: increase the VSTREAM buffer size if - * the VSTREAM buffer is smaller than the MSS. Note: the MSS may change - * when the route changes and IP path MTU discovery is turned on, so we - * choose a somewhat larger buffer. + * the default VSTREAM buffer size is smaller than the MSS. Note: the MSS + * may change when the route changes and IP path MTU discovery is turned + * on, so we choose a somewhat larger buffer. */ #ifdef VSTREAM_CTL_BUFSIZE - if (mss > 0) { + if (mss > VSTREAM_BUFSIZE) { if (mss < INT_MAX / 2) mss *= 2; vstream_control(fp,