This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU Mailutils".
http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=0ee00fd5861514e757aa73b1e62ca9896b2461ff The branch, stream-cleanup has been updated via 0ee00fd5861514e757aa73b1e62ca9896b2461ff (commit) from 2613500d4a50cf7d36e30eea6d7af915a38c8f7d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0ee00fd5861514e757aa73b1e62ca9896b2461ff Author: Sergey Poznyakoff <g...@gnu.org.ua> Date: Fri Apr 30 02:59:59 2010 +0300 Bugfixes in stream code. * mailbox/amd.c (amd_body_stream_seek): Fix boundary checking. Return ESPIPE on boundary error. * mailbox/header.c (header_seek): Likewise. * mailbox/memory_stream.c (_memory_seek): Likewise. * mailbox/message.c (_message_stream_seek): Likewise. * mailbox/message_stream.c (_message_seek): Likewise. * mailbox/stdio_stream.c (stdio_seek): Likewise. * mailbox/file_stream.c (fd_open): Invert error condition. Fix computation of open flags. Return immediately if open returns -1. (fd_seek): Fix boundary checking. Return ESPIPE on boundary error. * mailbox/mapfile_stream.c (_mapfile_open): Fix flags calculation. (_mapfile_seek): Fix boundary checking. Return ESPIPE on boundary error. * mailbox/streamref.c (_streamref_read): Fix calculation of the top size boundary. Return 0 bytes if seek returns ESPIPE. (_streamref_seek): Return ESPIPE on boundary error. * mailbox/base64.c (_base64_decoder, _base64_encoder): Do not dereference iobuf if cmd is mu_filter_init or mu_filter_done. * mailbox/binflt.c (_copy_codec, _bit7_coder): Likewise. * mailbox/crlfflt.c (_crlf_encoder, _crlf_decoder): Likewise. * mailbox/linelenflt.c (_ll_encoder): Likewise. * mailbox/qpflt.c (_qp_decoder, _qp_encoder): Likewise. * mailbox/mailcap.c (mu_mailcap_parse): Fix loop condition. ----------------------------------------------------------------------- Summary of changes: mailbox/amd.c | 4 ++-- mailbox/base64.c | 25 +++++++++++++++++-------- mailbox/binflt.c | 25 ++++++++++++++----------- mailbox/crlfflt.c | 32 +++++++++++++++++++++----------- mailbox/file_stream.c | 9 ++++++--- mailbox/header.c | 4 ++-- mailbox/linelenflt.c | 13 +++++++++---- mailbox/mailcap.c | 7 ++++--- mailbox/mapfile_stream.c | 6 +++--- mailbox/memory_stream.c | 4 ++-- mailbox/message.c | 2 +- mailbox/message_stream.c | 2 +- mailbox/qpflt.c | 25 +++++++++++++++++-------- mailbox/stdio_stream.c | 2 +- mailbox/streamref.c | 18 ++++++++++++++++-- 15 files changed, 116 insertions(+), 62 deletions(-) diff --git a/mailbox/amd.c b/mailbox/amd.c index 34e823f..befe43e 100644 --- a/mailbox/amd.c +++ b/mailbox/amd.c @@ -1652,8 +1652,8 @@ amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, break; } - if (off < 0 || off > size) - return EINVAL; + if (off < 0 || off >= size) + return ESPIPE; rc = mu_stream_seek (mhm->stream, mhm->body_start + off, MU_SEEK_SET, NULL); if (rc) diff --git a/mailbox/base64.c b/mailbox/base64.c index 156c4a8..fd0131e 100644 --- a/mailbox/base64.c +++ b/mailbox/base64.c @@ -114,10 +114,10 @@ _base64_decoder (void *xd MU_ARG_UNUSED, size_t consumed = 0; unsigned char data[4]; size_t nbytes = 0; - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const char *iptr; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -133,7 +133,12 @@ _base64_decoder (void *xd MU_ARG_UNUSED, iobuf->osize = 3; return mu_filter_moreoutput; } - + + iptr = iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + while (consumed < isize && nbytes + 3 < osize) { while (i < 4 && consumed < isize) @@ -179,9 +184,9 @@ _base64_encoder (void *xd MU_ARG_UNUSED, int pad = 0; const unsigned char *ptr = (const unsigned char*) iobuf->input; size_t nbytes = 0; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -208,6 +213,10 @@ _base64_encoder (void *xd MU_ARG_UNUSED, return mu_filter_moreoutput; } + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + while ((consumed + 3 <= isize && nbytes + 4 <= osize) || pad) { unsigned char c1 = 0, c2 = 0, x = '=', y = '='; diff --git a/mailbox/binflt.c b/mailbox/binflt.c index 003b665..d3de518 100644 --- a/mailbox/binflt.c +++ b/mailbox/binflt.c @@ -27,10 +27,7 @@ _copy_codec (void *xd MU_ARG_UNUSED, enum mu_filter_command cmd, struct mu_filter_io *iobuf) { - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + size_t osize; switch (cmd) { @@ -41,9 +38,10 @@ _copy_codec (void *xd MU_ARG_UNUSED, break; } - if (osize > isize) - osize = isize; - memcpy (optr, iptr, osize); + osize = iobuf->osize; + if (osize > iobuf->isize) + osize = iobuf->isize; + memcpy (iobuf->output, iobuf->input, osize); iobuf->isize = osize; iobuf->osize = osize; return mu_filter_ok; @@ -55,10 +53,10 @@ _bit7_coder (void *xd MU_ARG_UNUSED, struct mu_filter_io *iobuf) { size_t i; - const unsigned char *iptr = (const unsigned char *) iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const unsigned char *iptr; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -69,6 +67,11 @@ _bit7_coder (void *xd MU_ARG_UNUSED, break; } + iptr = (const unsigned char *) iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + if (osize > isize) osize = isize; for (i = 0; i < osize; i++) diff --git a/mailbox/crlfflt.c b/mailbox/crlfflt.c index a07e08d..3e9bab0 100644 --- a/mailbox/crlfflt.c +++ b/mailbox/crlfflt.c @@ -31,10 +31,10 @@ _crlf_encoder (void *xd MU_ARG_UNUSED, struct mu_filter_io *iobuf) { size_t i, j; - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const unsigned char *iptr; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -45,9 +45,14 @@ _crlf_encoder (void *xd MU_ARG_UNUSED, break; } + iptr = (const unsigned char *) iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + for (i = j = 0; i < isize && j < osize; i++) { - unsigned char c = *(unsigned char*)iptr++; + unsigned char c = *iptr++; if (c == '\n') { if (j + 1 == osize) @@ -80,10 +85,10 @@ _crlf_decoder (void *xd MU_ARG_UNUSED, struct mu_filter_io *iobuf) { size_t i, j; - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const unsigned char *iptr; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -94,14 +99,19 @@ _crlf_decoder (void *xd MU_ARG_UNUSED, break; } + iptr = (const unsigned char *) iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + for (i = j = 0; i < isize && j < osize; i++) { - unsigned char c = *(unsigned char*)iptr++; + unsigned char c = *iptr++; if (c == '\r') { if (i + 1 == isize) break; - if (*(unsigned char*)iptr == '\n') + if (*iptr == '\n') continue; } optr[j++] = c; diff --git a/mailbox/file_stream.c b/mailbox/file_stream.c index 69a5d6b..977004d 100644 --- a/mailbox/file_stream.c +++ b/mailbox/file_stream.c @@ -75,13 +75,13 @@ fd_open (struct _mu_stream *str) int oflg; int fd; - if (fstr->filename) + if (!fstr->filename) return EINVAL; if (fstr->fd != -1) fd_close (str); /* Map the flags to the system equivalent. */ - if (fstr->stream.flags & MU_STREAM_RDWR) + if ((fstr->stream.flags & MU_STREAM_RDWR) == MU_STREAM_RDWR) oflg = O_RDWR; else if (fstr->stream.flags & (MU_STREAM_WRITE|MU_STREAM_APPEND)) oflg = O_WRONLY; @@ -109,6 +109,9 @@ fd_open (struct _mu_stream *str) else fd = open (fstr->filename, oflg); + if (fd == -1) + return errno; + if (!(fstr->stream.flags & MU_STREAM_ALLOW_LINKS) && (fstr->stream.flags & (MU_STREAM_CREAT | MU_STREAM_RDWR | MU_STREAM_APPEND))) @@ -149,7 +152,7 @@ fd_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult) { struct _mu_file_stream *fstr = (struct _mu_file_stream *) str; off = lseek (fstr->fd, off, whence); - if (off <= 0) + if (off < 0) return errno; *presult = off; return 0; diff --git a/mailbox/header.c b/mailbox/header.c index 5d23a98..50ff83f 100644 --- a/mailbox/header.c +++ b/mailbox/header.c @@ -956,8 +956,8 @@ header_seek (mu_stream_t str, mu_off_t off, int whence, mu_off_t *presult) break; } - if (off < 0 || off > hstr->hdr->size) - return EINVAL; + if (off < 0 || off >= hstr->hdr->size) + return ESPIPE; hstr->off = off; return 0; } diff --git a/mailbox/linelenflt.c b/mailbox/linelenflt.c index b487553..e3817de 100644 --- a/mailbox/linelenflt.c +++ b/mailbox/linelenflt.c @@ -34,10 +34,10 @@ _ll_encoder (void *xd, struct mu_filter_io *iobuf) { struct _mu_linelen_filter *flt = xd; - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const char *iptr; + size_t isize; + char *optr; + size_t osize; size_t consumed, written; switch (cmd) @@ -50,6 +50,11 @@ _ll_encoder (void *xd, break; } + iptr = iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + for (consumed = written = 0; consumed < isize && written < osize; ) { char *p; diff --git a/mailbox/mailcap.c b/mailbox/mailcap.c index d0815b0..d9e96f2 100644 --- a/mailbox/mailcap.c +++ b/mailbox/mailcap.c @@ -510,9 +510,9 @@ mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream) size_t n; char *previous; char *buffer; - int buflen = 512; + size_t buflen = 512; - buffer = malloc (buflen * sizeof (*buffer)); + buffer = malloc (buflen); if (buffer == NULL) { return ENOMEM; @@ -532,7 +532,8 @@ mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream) if (status) return status; previous = NULL; - while ((status = mu_stream_readline (stream, buffer, buflen, &n)) == 0) + while ((status = mu_stream_readline (stream, buffer, buflen, &n)) == 0 + && n > 0) { int len; diff --git a/mailbox/mapfile_stream.c b/mailbox/mapfile_stream.c index 66bcca4..a54c65c 100644 --- a/mailbox/mapfile_stream.c +++ b/mailbox/mapfile_stream.c @@ -266,7 +266,7 @@ _mapfile_open (mu_stream_t stream) mfs->fd = -1; } /* Map the flags to the system equivalent */ - if (flags & MU_STREAM_RDWR) + if ((flags & MU_STREAM_RDWR) == MU_STREAM_RDWR) { mflag = PROT_READ | PROT_WRITE; flg = O_RDWR; @@ -331,8 +331,8 @@ _mapfile_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presu break; } - if (off < 0 || off > mfs->size) - return EINVAL; + if (off < 0 || off >= mfs->size) + return ESPIPE; mfs->offset = off; *presult = off; return 0; diff --git a/mailbox/memory_stream.c b/mailbox/memory_stream.c index 1f388fb..8e93e7b 100644 --- a/mailbox/memory_stream.c +++ b/mailbox/memory_stream.c @@ -185,8 +185,8 @@ _memory_seek (struct _mu_stream *stream, mu_off_t off, int whence, break; } - if (off < 0 || off > mfs->size) - return EINVAL; + if (off < 0) + return ESPIPE; mfs->offset = off; *presult = off; return 0; diff --git a/mailbox/message.c b/mailbox/message.c index b92815e..5d9a505 100644 --- a/mailbox/message.c +++ b/mailbox/message.c @@ -183,7 +183,7 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, int whence, break; } if (off < 0 || off >= size) - return EINVAL; + return ESPIPE; switch (sp->state) { diff --git a/mailbox/message_stream.c b/mailbox/message_stream.c index f5c3cc4..6b3cb7d 100644 --- a/mailbox/message_stream.c +++ b/mailbox/message_stream.c @@ -325,7 +325,7 @@ _message_seek (struct _mu_stream *stream, mu_off_t off, int whence, } if (off < 0 || off >= size) - return s->stream.last_err = EINVAL; + return ESPIPE; s->offset = off; *presult = off; return 0; diff --git a/mailbox/qpflt.c b/mailbox/qpflt.c index cde2688..4d8db53 100644 --- a/mailbox/qpflt.c +++ b/mailbox/qpflt.c @@ -33,10 +33,10 @@ _qp_decoder (void *xd MU_ARG_UNUSED, size_t consumed = 0; size_t wscount = 0; size_t nbytes = 0; - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const char *iptr; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -47,6 +47,11 @@ _qp_decoder (void *xd MU_ARG_UNUSED, break; } + iptr = iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; + while (consumed < isize && nbytes < osize) { c = *iptr++; @@ -159,10 +164,10 @@ _qp_encoder (void *xd MU_ARG_UNUSED, size_t consumed = 0; size_t nbytes = 0; static const char _hexdigits[] = "0123456789ABCDEF"; - const char *iptr = iobuf->input; - size_t isize = iobuf->isize; - char *optr = iobuf->output; - size_t osize = iobuf->osize; + const char *iptr; + size_t isize; + char *optr; + size_t osize; switch (cmd) { @@ -173,6 +178,10 @@ _qp_encoder (void *xd MU_ARG_UNUSED, break; } + iptr = iobuf->input; + isize = iobuf->isize; + optr = iobuf->output; + osize = iobuf->osize; nbytes = 0; /* Strategy: check if we have enough room in the output buffer only diff --git a/mailbox/stdio_stream.c b/mailbox/stdio_stream.c index d401270..dac196c 100644 --- a/mailbox/stdio_stream.c +++ b/mailbox/stdio_stream.c @@ -147,7 +147,7 @@ stdio_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult) } if (off < 0) - return EINVAL; + return ESPIPE; fs->offset = off; *presult = fs->offset; diff --git a/mailbox/streamref.c b/mailbox/streamref.c index 75d2209..04c8450 100644 --- a/mailbox/streamref.c +++ b/mailbox/streamref.c @@ -41,9 +41,17 @@ _streamref_read (struct _mu_stream *str, char *buf, size_t bufsize, struct _mu_streamref *sp = (struct _mu_streamref *)str; int rc; size_t nread; - rc = mu_stream_seek (sp->transport, sp->offset, MU_SEEK_SET, NULL); + mu_off_t off; + + rc = mu_stream_seek (sp->transport, sp->offset, MU_SEEK_SET, &off); if (rc == 0) { + if (sp->end) + { + size_t size = sp->end - off + 1; + if (size < bufsize) + bufsize = size; + } rc = mu_stream_read (sp->transport, buf, bufsize, &nread); if (rc == 0) { @@ -51,6 +59,12 @@ _streamref_read (struct _mu_stream *str, char *buf, size_t bufsize, *pnread = nread; } } + else if (rc == ESPIPE) + { + *pnread = 0; + str->flags |= _MU_STR_EOF; + return 0; + } return streamref_return (sp, rc); } @@ -143,7 +157,7 @@ _streamref_seek (struct _mu_stream *str, mu_off_t off, int whence, } if (off < 0 || off >= size) - return sp->stream.last_err = EINVAL; + return sp->stream.last_err = ESPIPE; rc = mu_stream_seek (sp->transport, sp->start + off, MU_SEEK_SET, &sp->offset); if (rc) hooks/post-receive -- GNU Mailutils _______________________________________________ Commit-mailutils mailing list Commit-mailutils@gnu.org http://lists.gnu.org/mailman/listinfo/commit-mailutils