aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-11-28 11:26:51 +0800
committerDan Winship <danw@src.gnome.org>2000-11-28 11:26:51 +0800
commit89ae418e500b8503bd8edddb60c5a429539404ee (patch)
tree27fe3048b93d9850670c85acb94aeeabb4e91cc9
parent26fccb498293b89b9bef804fc85436e00a4ee1cd (diff)
downloadgsoc2013-evolution-89ae418e500b8503bd8edddb60c5a429539404ee.tar.gz
gsoc2013-evolution-89ae418e500b8503bd8edddb60c5a429539404ee.tar.zst
gsoc2013-evolution-89ae418e500b8503bd8edddb60c5a429539404ee.zip
Make this gratuitously more complicated. No wait, I mean, fix bugs. Now
* providers/imap/camel-imap-command.c (imap_read_untagged): Make this gratuitously more complicated. No wait, I mean, fix bugs. Now fully handles NULs in the data stream (which "can't happen" but do) and also handles responses containing multiple literals. Also does less copying than the original code. * camel-stream-buffer.c (stream_read): Fix a bug that could make it lose sync and/or overrun buffers. svn path=/trunk/; revision=6688
-rw-r--r--camel/ChangeLog11
-rw-r--r--camel/camel-stream-buffer.c9
-rw-r--r--camel/providers/imap/camel-imap-command.c137
3 files changed, 105 insertions, 52 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 3a0310c555..f566620c1b 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,14 @@
+2000-11-27 Dan Winship <danw@helixcode.com>
+
+ * providers/imap/camel-imap-command.c (imap_read_untagged): Make
+ this gratuitously more complicated. No wait, I mean, fix bugs. Now
+ fully handles NULs in the data stream (which "can't happen" but
+ do) and also handles responses containing multiple literals. Also
+ does less copying than the original code.
+
+ * camel-stream-buffer.c (stream_read): Fix a bug that could make
+ it lose sync and/or overrun buffers.
+
2000-11-27 JP Rosevear <jpr@helixcode.com>
* providers/local/.cvsignore: shush
diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c
index 26d7d3197a..8641206006 100644
--- a/camel/camel-stream-buffer.c
+++ b/camel/camel-stream-buffer.c
@@ -247,12 +247,13 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
} else {
bytes_read = camel_stream_read(sbf->stream, sbf->buf, sbf->size);
if (bytes_read>0) {
+ size_t bytes_used = bytes_read > n ? n : bytes_read;
sbf->ptr = sbf->buf;
sbf->end = sbf->buf+bytes_read;
- memcpy(bptr, sbf->ptr, n);
- sbf->ptr += n;
- bptr += n;
- n -= bytes_read;
+ memcpy(bptr, sbf->ptr, bytes_used);
+ sbf->ptr += bytes_used;
+ bptr += bytes_used;
+ n -= bytes_used;
}
}
} else {
diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c
index e615453198..4f2b0ca500 100644
--- a/camel/providers/imap/camel-imap-command.c
+++ b/camel/providers/imap/camel-imap-command.c
@@ -228,78 +228,119 @@ imap_read_response (CamelImapStore *store, CamelException *ex)
}
/* Given a line that is the start of an untagged response, read and
- * return the complete response. (This will be a no-op if the line
- * in question doesn't end with a literal.)
- *
- * FIXME: this won't deal with multiple literals in a single response.
+ * return the complete response, which may include an arbitrary number
+ * of literals.
*/
static char *
imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex)
{
- int fulllen, length, left, i;
+ int fulllen, length, ldigits, nread, i;
GPtrArray *data;
- char *end, *p;
- int n;
+ GString *str;
+ char *end, *p, *s, *d;
p = strrchr (line, '{');
if (!p)
return line;
- length = strtoul (p + 1, &end, 10);
- if (*end != '}' || *(end + 1) || end == p + 1)
- return line;
-
- fulllen = length + strlen (line) + 1;
-
- /* OK. We have a literal. @length is the length including CRLF
- * pairs, which camel_remote_store_recv_line won't return.
- */
data = g_ptr_array_new ();
- g_ptr_array_add (data, line);
- left = length;
+ fulllen = 0;
+
while (1) {
- if ((n = camel_remote_store_recv_line (CAMEL_REMOTE_STORE (store), &line, ex)) < 0) {
- for (i = 0; i < data->len; i++)
- g_free (data->pdata[i]);
- g_ptr_array_free (data, TRUE);
- return NULL;
- }
- g_ptr_array_add (data, line);
+ str = g_string_new (line);
+ g_free (line);
+ fulllen += str->len;
+ g_ptr_array_add (data, str);
- if (left <= 0)
+ p = strrchr (str->str, '{');
+ if (!p)
break;
-
- left -= n + 2;
-
- /* The output string will have only LF, not CRLF, so
- * decrement the length by one.
+
+ length = strtoul (p + 1, &end, 10);
+ if (*end != '}' || *(end + 1) || end == p + 1)
+ break;
+ ldigits = end - (p + 1);
+
+ /* Read the literal */
+ str = g_string_sized_new (length + 2);
+ str->str[0] = '\n';
+ nread = camel_stream_read (CAMEL_REMOTE_STORE (store)->istream,
+ str->str + 1, length);
+ if (nread < length) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("Server response ended too soon."));
+ camel_service_disconnect (CAMEL_SERVICE (store),
+ FALSE, NULL);
+ goto lose;
+ }
+ str->str[length] = '\0';
+
+ /* Fix up the literal, turning CRLFs into LF. Also, if
+ * we find any embedded NULs, strip them. This is
+ * dubious, but:
+ * - The IMAP grammar says you can't have NULs here
+ * anyway, so this will not affect our behavior
+ * against any completely correct server.
+ * - WU-imapd 12.264 (at least) will cheerily pass
+ * NULs along if they are embedded in the message
+ * - The only cause of embedded NULs we've seen is an
+ * Evolution base64-encoder bug that sometimes
+ * inserts a NUL into the last line when it
+ * shouldn't.
+ */
+
+ s = d = str->str + 1;
+ end = str->str + 1 + length;
+ while (s < end) {
+ while (*s == '\0' && s < end) {
+ s++;
+ length--;
+ }
+ if (*s == '\r' && *(s + 1) == '\n') {
+ s++;
+ length--;
+ }
+ *d++ = *s++;
+ }
+ *d = '\0';
+ str->len = length + 1;
+
+ /* p points to the "{" in the line that starts the
+ * literal. The length of the CR-less response must be
+ * less than or equal to the length of the response
+ * with CRs, therefore overwriting the old value with
+ * the new value cannot cause an overrun. However, we
+ * don't want it to be shorter either, because then the
+ * GString's length would be off...
*/
- length--;
+ sprintf (p, "{%0*d}", ldigits, str->len);
+
+ fulllen += str->len;
+ g_ptr_array_add (data, str);
+
+ /* Read the next line. */
+ if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (store),
+ &line, ex) < 0)
+ goto lose;
}
-
- /* Add the length of the post-literal line. */
- fulllen += n;
-
- /* p points to the "{" in the line that starts the literal.
- * The length of the CR-less response must be less than or
- * equal to the length of the response with CRs, therefore
- * overwriting the old value with the new value cannot cause
- * an overrun.
- */
- sprintf (p, "{%d}", length);
/* Now reassemble the data. */
p = line = g_malloc (fulllen + 1);
for (i = 0; i < data->len; i++) {
- length = strlen (data->pdata[i]);
- memcpy (p, data->pdata[i], length);
- g_free (data->pdata[i]);
- p += length;
- *p++ = '\n';
+ str = data->pdata[i];
+ memcpy (p, str->str, str->len);
+ p += str->len;
+ g_string_free (str, TRUE);
}
*p = '\0';
g_ptr_array_free (data, TRUE);
return line;
+
+ lose:
+ for (i = 0; i < data->len; i++)
+ g_string_free (data->pdata[i], TRUE);
+ g_ptr_array_free (data, TRUE);
+ return NULL;
}
ions'>-13/+9 * - Add STAGEDIR to portdb2013-12-293-16/+23 * - Use distribution from sourceforge which updates us to 3.2.0db2013-12-2921-212/+319 * Enable stage supportjohans2013-12-292-12/+13 * Remove useless dancing of pre.mk/post.mkbapt2013-12-291-3/+1 * - convert to stagedb2013-12-282-12/+10 * - convert to use stagedb2013-12-283-21/+79 * - convert to stagedb2013-12-283-20/+72 * - convert to stagedb2013-12-282-18/+13 * Horde package update:mm2013-12-282-3/+3 * - Add LICENSEdb2013-12-283-11/+8 * - Fix usrp on 10.0db2013-12-262-22/+105 * Update freetype to 2.5.2.kwm2013-12-251-0/+4 * - convert to stagedb2013-12-222-11/+7 * - Add stagedir supportdb2013-12-211-8/+4 * Fix LIB_DEPENDSantoine2013-12-201-1/+1 * Use dos2unix USES macro.ehaupt2013-12-181-1/+1 * - use STAGEDIRdinoex2013-12-172-77/+102 * - Fix build on 10db2013-12-163-20/+30 * Specify which BSD licence applies.rene2013-12-161-1/+1 * Update to 1.1.1rene2013-12-152-4/+4 * - Fix build on 10db2013-12-1518-4/+453 * - Correct a mis-use of USES=db2013-12-131-2/+1 * - Update to latest version [1]db2013-12-139-85/+130 * In preparation for making libtool generate libraries with a sane name, fix allbapt2013-12-1133-76/+76 * Include patches from git repo to avoid keeling overcrees2013-12-082-14/+131 * - Fix build on 10.xdb2013-12-0821-10/+345 * - Update WWW after forum update.nox2013-12-052-2/+2 * * Update to 1.1.0:rene2013-12-043-12/+8 * - Modernize the port: uses USES, etc.eadler2013-12-022-27/+5 * Remove expired ports:rene2013-12-019-150/+0 * Stage support for non-IGNORED pear classesantoine2013-11-262-2/+0 * - use STAGEDIRdinoex2013-11-234-3/+70 * - Pass QMAKE_ARGS to qmakemakc2013-11-222-28/+22 * - Convert to USES=qmake (and other USES while I'm here)makc2013-11-222-24/+15 * Horde package update:mm2013-11-222-3/+3 * Update to version 3.1.1.bsam2013-11-223-7/+10 * - Change maintainer email to @FreeBSD.orgnemysis2013-11-191-11/+7 * Convert to USES=dos2unixbapt2013-11-182-5/+3 * - Update from 2.0.10 to 2.0.11danilo2013-11-182-6/+6 * Support STAGEDIR.vanilla2013-11-1831-120/+304 * - Add LICENSEsunpoet2013-11-153-18/+22 * - Switch to USES=gmake.olgeni2013-11-111-5/+19 * Convert to USES=kmod, which removes duplicated code and ensures that allrene2013-11-102-11/+5 * Update to 0.3.6.kwm2013-11-082-2/+4 * - Enable stagingmartymac2013-11-082-15/+14 * Support STAGEDIR.vanilla2013-11-056-26/+20 * comms/deforaos-phone: update to 0.3.12wg2013-11-054-14/+55 * - Fix stagedirdb2013-11-053-14/+21 * Stagify Gstreamer ports.kwm2013-11-021-1/+0 * - Update to version 2.9.1pawel2013-11-022-17/+16 * None of the binaries installed by comms/libimobiledevice are actually linkeddanfe2013-10-312-17/+18 * Respect $(CC).ale2013-10-301-2/+20 * - Perform general cleanup:eadler2013-10-304-7/+5 * - Convert to stagingeadler2013-10-301-11/+6 * - Convert to stagingeadler2013-10-301-5/+1 * - Add stage supportswills2013-10-302-2/+0 * - Update to 1.0.5rene2013-10-294-33/+11 * - use STAGEDIRdinoex2013-10-281-6/+6 * Revert USE_GCC to yespawel2013-10-281-1/+1 * Update to libmpc version 1.0.1 which brings the following fixes:gerald2013-10-269-7/+9 * - fix build with clangdinoex2013-10-252-10/+56 * Support staging.ehaupt2013-10-241-4/+3 * - Convert to USES+=tkgahr2013-10-233-10/+19 * Convert to OptionsNG and stagify.danfe2013-10-231-16/+15 * - Support staging.tijl2013-10-232-19/+11 * Horde package update:mm2013-10-232-3/+3 * - Support staging.tijl2013-10-231-15/+11 * - Support staging.tijl2013-10-231-12/+8 * - Convert to stagingmadpilot2013-10-227-58/+82 * - Remove manual creation and removal of share/applications, as it's now in th...amdmi32013-10-2213-13/+0 * comms/dabstick-radio: unset FFMPEG_SUFFIXwg2013-10-221-5/+2 * Horde port update:mm2013-10-212-3/+3 * - Backport patch to fix build of py-libimobiledevice.avilla2013-10-142-2/+12 * Horde package update:mm2013-10-112-3/+3 * - Update comms/rtl-sdr to 20130913 and bump dependent ports' revisionsmartymac2013-10-105-114/+109 * - Change maintainer email to @FreeBSD.orgdanilo2013-10-073-84/+203 * Removed unmaintained (ports@) or gnome@ ports depending on gnome1bapt2013-10-058-94/+0 * Remove the version 1.03 of the mlan API.phk2013-10-0511-471/+0 * umcs7840 was removed 3 Oct 2013 14:25:41 +0000 (UTC).linimon2013-10-041-1/+0 * Remove comms/umcs7840, this driver is included in base system long time ago.lev2013-10-035-65/+0 * - Add DOCS Optionnemysis2013-10-032-23/+19 * - update USE_GMAKE to USES= gmakedb2013-09-301-3/+1 * - Support stagingmadpilot2013-09-292-34/+22 * - Support stagingmadpilot2013-09-291-5/+3 * - Support stagingmadpilot2013-09-291-10/+3 * Support staging.naddy2013-09-292-8/+1 * Add staging support.rene2013-09-282-4/+29 * - Fix build under Freebsd-10db2013-09-281-0/+1 * - Add support for STAGEDIRpawel2013-09-272-12/+3 * - Remove NO_STAGE as these have been tested to be safebdrewery2013-09-251-1/+0 * - Convert to USES+=tkgahr2013-09-251-1/+1 * STAGE'ify comms/libmodbus.bsam2013-09-242-29/+56 * - fix misplaced NO_STAGE in slaveports and ifdefsdinoex2013-09-213-3/+5 * Add NO_STAGE all over the place in preparation for the staging support (cat: ...bapt2013-09-21172-210/+215 * SSP support has been added to ports with WITH_SSP for i386 and amd64bdrewery2013-09-202-5/+5 * - Add missing iconv USESmadpilot2013-09-181-1/+1 * Fix build under 10-CURRENT.cy2013-09-181-0/+23 * Convert to new perl frameworkbapt2013-09-172-3/+2 * - Respect CC: fix build on -head (with clang)sunpoet2013-09-163-15/+13 * - convert to the new perl5 frameworkaz2013-09-1214-74/+38 * - convert to the new perl5 frameworkaz2013-09-123-18/+9 * Add explicit dependency on pkgconf (27 ports)marino2013-09-121-5/+2 * Add explicit dependency on pkgconf (6 ports)marino2013-09-111-6/+2 * Update to 1.0.4 :rene2013-09-112-4/+4 * Horde package update:mm2013-09-092-3/+3 * Add an explicit dependency on pkgconfbapt2013-09-061-6/+2 * - Make ports use the libc provided iconv implementation on 10-CURRENTmadpilot2013-09-053-2/+5 * - Use new Makefile header formatmartymac2013-09-041-5/+4 * Horde package update:mm2013-09-042-3/+3 * Add an explicit dependency on pkgconfbapt2013-09-031-0/+1 * Add an explicit dependency on pkgconfbapt2013-09-034-2/+4 * Add an explicit dependency on pkgconfbapt2013-09-031-1/+1 * Add an explicit dependency on pkgconfbapt2013-09-032-10/+4 * Add an explicit dependency on pkgconfbapt2013-09-031-2/+1 * Add an explicit dependency on pkgconfbapt2013-09-032-3/+2 * Add an explicit dependency on pkgconfbapt2013-09-021-0/+1 * Add an explicit dependency on pkgconfbapt2013-09-021-5/+2 * Eliminate USE_GNOME=pkgconfig from commsbapt2013-09-022-3/+3 * Add an explicit dependency on pkgconfigbapt2013-09-021-2/+1 * - Resolve of using USE_PERL5 and PERL_CONFIGURE togetheraz2013-09-021-6/+3 * Remove expired ports:rene2013-09-0110-135/+0 * Update comms/pear-Horde_ActiveSync to 2.7.0mm2013-09-012-3/+3 * - Switch to new LIB_DEPENDS formatpawel2013-08-291-2/+2 * - Remove bogus conditional IGNORE for PACKAGE_BUILDING; these shouldbdrewery2013-08-291-2/+0 * - Don't attempt to build when PACKAGE_BUILDING, just hitsbdrewery2013-08-291-1/+1 * Update math/gsl to 1.16 and adjust some dependent portsbf2013-08-271-0/+1 * Remove expired ports:rene2013-08-269-170/+0 * Horde package update:mm2013-08-232-3/+3 * - Update to 1.10.0sunpoet2013-08-211-1/+1 * - Update x11-toolkits/c++-gtk-utils to 2.2.2pawel2013-08-211-1/+2 * Replace USE_GCC=4.6+ and USE_GCC=4.4+ by USE_GCC=yes.gerald2013-08-183-3/+3 * - restore qsstv and update to latestdb2013-08-1514-0/+233 * - Remove MAKE_JOBS_SAFE variableak2013-08-1514-14/+0 * - Update to 0.96 .nox2013-08-155-105/+157 * - Add patch to avoid a bus error while starting the software.madpilot2013-08-142-2/+21 * Mark MAKE_JOBS_UNSAFE.ale2013-08-131-0/+2 * Horde package update:mm2013-08-102-3/+3 * - Update to 1.7.1madpilot2013-08-073-11/+9 * We never actually build the GTK frontend anyway. If anyone would like thecrees2013-08-051-2/+2 * - Convert to new perl frameworkaz2013-08-034-9/+8 * Fix build with newer binutilsbapt2013-08-021-1/+1 * For all my portsnaddy2013-08-021-1/+0 * comms/xlog: update to 2.0.10wg2013-08-012-3/+4 * Fix build with clang by forcing gnu89bapt2013-07-301-0/+1 * - Update post-install message to move /usr/local/share/tqsldb2013-07-281-1/+1 * Mark as broken if the XCWCP option is selected which uses the removed QT3.rene2013-07-271-0/+1 * KDE3 and QT3 expired on 2013-07-01, remove these ports.rene2013-07-27