From 75bd318f5a0ec48378d99fe741a9a60ab23e0b51 Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Thu, 19 Sep 2002 17:36:44 +0000 Subject: [PATCH] sync with 0.8.3cvs3 --- ChangeLog | 13 +++++++++++ ChangeLog.claws | 5 +++++ ChangeLog.jp | 12 ++++++++++ configure.in | 2 +- src/rfc2015.c | 49 ++++++++++++++++++++++++++++++++++++----- src/utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ src/utils.h | 4 ++++ 7 files changed, 136 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index f30b3f5dc..db6eaf2ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2002-09-19 + + * src/rfc2015.c: check_signature(): corrected error handling and + fixed memory leak. + +2002-09-19 + + * src/rfc2015.c: check_signature(): correctly remove the last empty + line, and canonicalize the file part before verifying (this should + fix incompatibility with Evolution or some other MUAs). + * src/utils.[ch]: copy_file_part(): new. It copies the specified + range of file stream to another file. + 2002-09-19 * src/compose.c: compose_write_to_file(): force BASE64 encoding for diff --git a/ChangeLog.claws b/ChangeLog.claws index ac1b888c6..df3915b04 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2002-09-19 [paul] 0.8.2claws60 + + * sync with 0.8.2cvs3 + see ChangeLog 2002-09-19 + 2002-09-19 [paul] 0.8.2claws59 * src/prefs_folder_item.c diff --git a/ChangeLog.jp b/ChangeLog.jp index 873451915..485cc4c64 100644 --- a/ChangeLog.jp +++ b/ChangeLog.jp @@ -1,3 +1,15 @@ +2002-09-19 + + * src/rfc2015.c: check_signature(): ¥¨¥é¡¼½èÍý¤È¥á¥â¥ê¥ê¡¼¥¯¤ò½¤Àµ¡£ + +2002-09-19 + + * src/rfc2015.c: check_signature(): ¸¡¾ÚÁ°¤Ë¥Õ¥¡¥¤¥ë¥Ñ¡¼¥È¤ÎºÇ¸å¤Î + ¶õ¹Ô¤òÀµ¤·¤¯½üµî¤·¡¢Àµµ¬²½¤¹¤ë¤è¤¦¤Ë¤·¤¿(Evolution ¤½¤Î¾ MUA + ¤È¤ÎÈó¸ß´¹À­¤ò²ò¾Ã¤¹¤ë¤Ï¤º)¡£ + * src/utils.[ch]: copy_file_part(): ¿·µ¬¡£»ØÄꤷ¤¿ÈϰϤΥե¡¥¤¥ë + ¥¹¥È¥ê¡¼¥à¤òÊ̤Υե¡¥¤¥ë¤Ë¥³¥Ô¡¼¤¹¤ë¡£ + 2002-09-19 * src/compose.c: compose_write_to_file(): 8-bit ¥Æ¥­¥¹¥È¤Î½ð̾»þ¤Ë diff --git a/configure.in b/configure.in index 252c6603a..89630538d 100644 --- a/configure.in +++ b/configure.in @@ -10,7 +10,7 @@ MINOR_VERSION=8 MICRO_VERSION=2 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws59 +EXTRA_VERSION=claws60 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/rfc2015.c b/src/rfc2015.c index 2f89a7da9..527c64a3e 100644 --- a/src/rfc2015.c +++ b/src/rfc2015.c @@ -278,6 +278,8 @@ static void check_signature (MimeInfo *mimeinfo, MimeInfo *partinfo, FILE *fp) GpgmeSigStat status = GPGME_SIG_STAT_NONE; GpgmegtkSigStatus statuswindow = NULL; const char *result = NULL; + gchar *tmp_file; + gint n_exclude_chars = 0; if (prefs_common.gpg_signature_popup) statuswindow = gpgmegtk_sig_status_create (); @@ -288,12 +290,47 @@ static void check_signature (MimeInfo *mimeinfo, MimeInfo *partinfo, FILE *fp) goto leave; } - /* don't include the last character (LF). It does not belong to the - * signed text */ - err = gpgme_data_new_from_filepart (&text, NULL, fp, - mimeinfo->children->fpos, - mimeinfo->children->size ? - (mimeinfo->children->size - 1) : 0 ); + /* don't include the last empty line. + It does not belong to the signed text */ + if (mimeinfo->children->size > 0) { + if (fseek(fp, mimeinfo->children->fpos + mimeinfo->children->size - 1, + SEEK_SET) < 0) { + perror("fseek"); + goto leave; + } + if (fgetc(fp) == '\n') { + n_exclude_chars++; + if (mimeinfo->children->size > 1) { + if (fseek(fp, mimeinfo->children->fpos + mimeinfo->children->size - 2, + SEEK_SET) < 0) { + perror("fseek"); + goto leave; + } + if (fgetc(fp) == '\r') + n_exclude_chars++; + } + } + } + + /* canonicalize the file part. */ + tmp_file = get_tmp_file(); + if (copy_file_part(fp, mimeinfo->children->fpos, + mimeinfo->children->size - n_exclude_chars, + tmp_file) < 0) { + g_free(tmp_file); + goto leave; + } + if (canonicalize_file_replace(tmp_file) < 0) { + unlink(tmp_file); + g_free(tmp_file); + goto leave; + } + + err = gpgme_data_new_from_file(&text, tmp_file, 1); + + unlink(tmp_file); + g_free(tmp_file); + if (!err) err = gpgme_data_new_from_filepart (&sig, NULL, fp, partinfo->fpos, partinfo->size); diff --git a/src/utils.c b/src/utils.c index 39b99fec1..ae2496715 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2104,6 +2104,64 @@ gint move_file(const gchar *src, const gchar *dest, gboolean overwrite) return 0; } +gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) +{ + FILE *dest_fp; + gint n_read; + gint bytes_left, to_read; + gchar buf[BUFSIZ]; + gboolean err = FALSE; + + if (fseek(fp, offset, SEEK_SET) < 0) { + perror("fseek"); + return -1; + } + + if ((dest_fp = fopen(dest, "wb")) == NULL) { + FILE_OP_ERROR(dest, "fopen"); + return -1; + } + + if (change_file_mode_rw(dest_fp, dest) < 0) { + FILE_OP_ERROR(dest, "chmod"); + g_warning("can't change file mode\n"); + } + + bytes_left = length; + to_read = MIN(bytes_left, sizeof(buf)); + + while ((n_read = fread(buf, sizeof(gchar), to_read, fp)) > 0) { + if (n_read < to_read && ferror(fp)) + break; + if (fwrite(buf, n_read, 1, dest_fp) < 1) { + g_warning(_("writing to %s failed.\n"), dest); + fclose(dest_fp); + unlink(dest); + return -1; + } + bytes_left -= n_read; + if (bytes_left == 0) + break; + to_read = MIN(bytes_left, sizeof(buf)); + } + + if (ferror(fp)) { + perror("fread"); + err = TRUE; + } + if (fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "fclose"); + err = TRUE; + } + + if (err) { + unlink(dest); + return -1; + } + + return 0; +} + /* convert line endings into CRLF. If the last line doesn't end with * linebreak, add it. */ diff --git a/src/utils.h b/src/utils.h index 94b9d3d2e..fa7ee023b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -336,6 +336,10 @@ gint copy_file (const gchar *src, gint move_file (const gchar *src, const gchar *dest, gboolean overwrite); +gint copy_file_part (FILE *fp, + off_t offset, + size_t length, + const gchar *dest); gint canonicalize_file (const gchar *src, const gchar *dest); gint canonicalize_file_replace (const gchar *file); -- 2.25.1