2007-10-04 [colin] 3.0.2cvs9
authorColin Leroy <colin@colino.net>
Thu, 4 Oct 2007 17:36:57 +0000 (17:36 +0000)
committerColin Leroy <colin@colino.net>
Thu, 4 Oct 2007 17:36:57 +0000 (17:36 +0000)
* src/action.c
* src/addrbook.c
* src/addrindex.c
* src/compose.c
* src/exporthtml.c
* src/exportldif.c
* src/folder.c
* src/main.c
* src/matcher.c
* src/mbox.c
* src/messageview.c
* src/mh.c
* src/news.c
* src/partial_download.c
* src/pop.c
* src/procmime.c
* src/procmsg.c
* src/toolbar.c
* src/common/log.c
* src/common/mgutils.c
* src/common/plugin.c
* src/common/utils.c
* src/common/xml.c
* src/common/xml.h
* src/common/xmlprops.c
* src/common/xmlprops.h
* src/plugins/bogofilter/bogofilter.c
* src/plugins/clamav/clamav_plugin.c
* src/plugins/dillo_viewer/dillo_prefs.c
* src/plugins/pgpcore/prefs_gpg.c
* src/plugins/pgpinline/pgpinline.c
* src/plugins/pgpmime/pgpmime.c
* src/plugins/spamassassin/spamassassin.c
* src/plugins/trayicon/trayicon_prefs.c
Verify success on writes. Will fix possible strange
failure on disk full.

37 files changed:
ChangeLog
PATCHSETS
configure.ac
src/action.c
src/addrbook.c
src/addrindex.c
src/common/log.c
src/common/mgutils.c
src/common/plugin.c
src/common/utils.c
src/common/xml.c
src/common/xml.h
src/common/xmlprops.c
src/common/xmlprops.h
src/compose.c
src/exporthtml.c
src/exportldif.c
src/folder.c
src/main.c
src/matcher.c
src/mbox.c
src/messageview.c
src/mh.c
src/news.c
src/partial_download.c
src/plugins/bogofilter/bogofilter.c
src/plugins/clamav/clamav_plugin.c
src/plugins/dillo_viewer/dillo_prefs.c
src/plugins/pgpcore/prefs_gpg.c
src/plugins/pgpinline/pgpinline.c
src/plugins/pgpmime/pgpmime.c
src/plugins/spamassassin/spamassassin.c
src/plugins/trayicon/trayicon_prefs.c
src/pop.c
src/procmime.c
src/procmsg.c
src/toolbar.c

index b196e92..728940c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2007-10-04 [colin]     3.0.2cvs9
+
+       * src/action.c
+       * src/addrbook.c
+       * src/addrindex.c
+       * src/compose.c
+       * src/exporthtml.c
+       * src/exportldif.c
+       * src/folder.c
+       * src/main.c
+       * src/matcher.c
+       * src/mbox.c
+       * src/messageview.c
+       * src/mh.c
+       * src/news.c
+       * src/partial_download.c
+       * src/pop.c
+       * src/procmime.c
+       * src/procmsg.c
+       * src/toolbar.c
+       * src/common/log.c
+       * src/common/mgutils.c
+       * src/common/plugin.c
+       * src/common/utils.c
+       * src/common/xml.c
+       * src/common/xml.h
+       * src/common/xmlprops.c
+       * src/common/xmlprops.h
+       * src/plugins/bogofilter/bogofilter.c
+       * src/plugins/clamav/clamav_plugin.c
+       * src/plugins/dillo_viewer/dillo_prefs.c
+       * src/plugins/pgpcore/prefs_gpg.c
+       * src/plugins/pgpinline/pgpinline.c
+       * src/plugins/pgpmime/pgpmime.c
+       * src/plugins/spamassassin/spamassassin.c
+       * src/plugins/trayicon/trayicon_prefs.c
+               Verify success on writes. Will fix possible strange
+               failure on disk full.
+
 2007-10-04 [paul]      3.0.2cvs8
 
        * manual/advanced.xml
index 3c04640..056d214 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.2.4.20 -r 1.2.4.21 src/common/template.c;  ) > 3.0.2cvs6.patchset
 ( cvs diff -u -r 1.61.2.70 -r 1.61.2.71 src/account.c;  ) > 3.0.2cvs7.patchset
 ( cvs diff -u -r 1.1.2.41 -r 1.1.2.42 manual/advanced.xml;  ) > 3.0.2cvs8.patchset
+( cvs diff -u -r 1.12.2.48 -r 1.12.2.49 src/action.c;  cvs diff -u -r 1.22.2.16 -r 1.22.2.17 src/addrbook.c;  cvs diff -u -r 1.28.2.31 -r 1.28.2.32 src/addrindex.c;  cvs diff -u -r 1.382.2.412 -r 1.382.2.413 src/compose.c;  cvs diff -u -r 1.5.2.22 -r 1.5.2.23 src/exporthtml.c;  cvs diff -u -r 1.1.4.17 -r 1.1.4.18 src/exportldif.c;  cvs diff -u -r 1.213.2.164 -r 1.213.2.165 src/folder.c;  cvs diff -u -r 1.115.2.168 -r 1.115.2.169 src/main.c;  cvs diff -u -r 1.75.2.49 -r 1.75.2.50 src/matcher.c;  cvs diff -u -r 1.28.2.38 -r 1.28.2.39 src/mbox.c;  cvs diff -u -r 1.94.2.153 -r 1.94.2.154 src/messageview.c;  cvs diff -u -r 1.79.2.63 -r 1.79.2.64 src/mh.c;  cvs diff -u -r 1.101.2.40 -r 1.101.2.41 src/news.c;  cvs diff -u -r 1.1.2.20 -r 1.1.2.21 src/partial_download.c;  cvs diff -u -r 1.56.2.56 -r 1.56.2.57 src/pop.c;  cvs diff -u -r 1.49.2.98 -r 1.49.2.99 src/procmime.c;  cvs diff -u -r 1.150.2.103 -r 1.150.2.104 src/procmsg.c;  cvs diff -u -r 1.43.2.83 -r 1.43.2.84 src/toolbar.c;  cvs diff -u -r 1.6.2.17 -r 1.6.2.18 src/common/log.c;  cvs diff -u -r 1.1.4.7 -r 1.1.4.8 src/common/mgutils.c;  cvs diff -u -r 1.13.2.31 -r 1.13.2.32 src/common/plugin.c;  cvs diff -u -r 1.36.2.115 -r 1.36.2.116 src/common/utils.c;  cvs diff -u -r 1.1.4.21 -r 1.1.4.22 src/common/xml.c;  cvs diff -u -r 1.1.4.11 -r 1.1.4.12 src/common/xml.h;  cvs diff -u -r 1.1.4.6 -r 1.1.4.7 src/common/xmlprops.c;  cvs diff -u -r 1.2.2.5 -r 1.2.2.6 src/common/xmlprops.h;  cvs diff -u -r 1.1.2.34 -r 1.1.2.35 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.13.2.34 -r 1.13.2.35 src/plugins/clamav/clamav_plugin.c;  cvs diff -u -r 1.5.2.16 -r 1.5.2.17 src/plugins/dillo_viewer/dillo_prefs.c;  cvs diff -u -r 1.1.2.27 -r 1.1.2.28 src/plugins/pgpcore/prefs_gpg.c;  cvs diff -u -r 1.1.2.35 -r 1.1.2.36 src/plugins/pgpinline/pgpinline.c;  cvs diff -u -r 1.1.2.50 -r 1.1.2.51 src/plugins/pgpmime/pgpmime.c;  cvs diff -u -r 1.18.2.57 -r 1.18.2.58 src/plugins/spamassassin/spamassassin.c;  cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/plugins/trayicon/trayicon_prefs.c;  ) > 3.0.2cvs9.patchset
index 792387e..0172802 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=8
+EXTRA_VERSION=9
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 24374fb..638fe30 100644 (file)
@@ -848,14 +848,14 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                                           "Pipe creation failed.\n%s"),
                                        g_strerror(errno));
                        /* Closing fd = -1 fails silently */
-                       close(chld_in[0]);
-                       close(chld_in[1]);
-                       close(chld_out[0]);
-                       close(chld_out[1]);
-                       close(chld_err[0]);
-                       close(chld_err[1]);
-                       close(chld_status[0]);
-                       close(chld_status[1]);
+                       (void)close(chld_in[0]);
+                       (void)close(chld_in[1]);
+                       (void)close(chld_out[0]);
+                       (void)close(chld_out[1]);
+                       (void)close(chld_err[0]);
+                       (void)close(chld_err[1]);
+                       (void)close(chld_status[0]);
+                       (void)close(chld_status[1]);
                        return NULL; /* Pipe error */
                }
        }
@@ -869,7 +869,7 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                        perror("setpgid");
 
 #ifdef GDK_WINDOWING_X11
-               close(ConnectionNumber(gdk_display));
+               (void)close(ConnectionNumber(gdk_display));
 #endif /* GDK_WINDOWING_X11 */
 
                gch_pid = fork();
@@ -883,21 +883,21 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                                    (ACTION_PIPE_IN |
                                     ACTION_USER_IN |
                                     ACTION_USER_HIDDEN_IN)) {
-                                       close(fileno(stdin));
-                                       dup  (chld_in[0]);
+                                       (void)close(fileno(stdin));
+                                       (void)dup  (chld_in[0]);
                                }
-                               close(chld_in[0]);
-                               close(chld_in[1]);
-
-                               close(fileno(stdout));
-                               dup  (chld_out[1]);
-                               close(chld_out[0]);
-                               close(chld_out[1]);
-
-                               close(fileno(stderr));
-                               dup  (chld_err[1]);
-                               close(chld_err[0]);
-                               close(chld_err[1]);
+                               (void)close(chld_in[0]);
+                               (void)close(chld_in[1]);
+
+                               (void)close(fileno(stdout));
+                               (void)dup  (chld_out[1]);
+                               (void)close(chld_out[0]);
+                               (void)close(chld_out[1]);
+
+                               (void)close(fileno(stderr));
+                               (void)dup  (chld_err[1]);
+                               (void)close(chld_err[0]);
+                               (void)close(chld_err[1]);
                        }
 
                        cmdline[0] = "sh";
@@ -917,24 +917,24 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                        _exit(1);
                } else if (gch_pid < (pid_t) 0) { /* Fork error */
                        if (sync)
-                               write(chld_status[1], "1\n", 2);
+                               (void)write(chld_status[1], "1\n", 2);
                        perror("fork");
                        _exit(1);
                } else { /* Child */
                        if (sync) {
-                               close(chld_in[0]);
-                               close(chld_in[1]);
-                               close(chld_out[0]);
-                               close(chld_out[1]);
-                               close(chld_err[0]);
-                               close(chld_err[1]);
-                               close(chld_status[0]);
+                               (void)close(chld_in[0]);
+                               (void)close(chld_in[1]);
+                               (void)close(chld_out[0]);
+                               (void)close(chld_out[1]);
+                               (void)close(chld_err[0]);
+                               (void)close(chld_err[1]);
+                               (void)close(chld_status[0]);
 
                                debug_print("Child: waiting for grandchild\n");
                                waitpid(gch_pid, NULL, 0);
                                debug_print("Child: grandchild ended\n");
-                               write(chld_status[1], "0\n", 2);
-                               close(chld_status[1]);
+                               (void)write(chld_status[1], "0\n", 2);
+                               (void)close(chld_status[1]);
                        }
                        _exit(0);
                }
@@ -952,13 +952,13 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                return NULL;
        }
 
-       close(chld_in[0]);
+       (void)close(chld_in[0]);
        if (!(children->action_type &
              (ACTION_PIPE_IN | ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
-               close(chld_in[1]);
-       close(chld_out[1]);
-       close(chld_err[1]);
-       close(chld_status[1]);
+               (void)close(chld_in[1]);
+       (void)close(chld_out[1]);
+       (void)close(chld_err[1]);
+       (void)close(chld_status[1]);
 
        child_info = g_new0(ChildInfo, 1);
 
@@ -989,13 +989,13 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
                ret_str = g_locale_from_utf8(msg_str, strlen(msg_str),
                                             &by_read, &by_written, NULL);
                if (ret_str && by_written) {
-                       write(chld_in[1], ret_str, strlen(ret_str));
+                       (void)write(chld_in[1], ret_str, strlen(ret_str));
                        g_free(ret_str);
                } else
-                       write(chld_in[1], msg_str, strlen(msg_str));
+                       (void)write(chld_in[1], msg_str, strlen(msg_str));
                if (!(children->action_type &
                      (ACTION_USER_IN | ACTION_USER_HIDDEN_IN)))
-                       close(chld_in[1]);
+                       (void)close(chld_in[1]);
                child_info->chld_in = -1; /* No more input */
        }
 
@@ -1112,13 +1112,13 @@ static void childinfo_close_pipes(ChildInfo *child_info)
                gdk_input_remove(child_info->tag_err);
 
        if (child_info->chld_in >= 0)
-               close(child_info->chld_in);
+               (void)close(child_info->chld_in);
        if (child_info->chld_out >= 0)
-               close(child_info->chld_out);
+               (void)close(child_info->chld_out);
        if (child_info->chld_err >= 0)
-               close(child_info->chld_err);
+               (void)close(child_info->chld_err);
 
-       close(child_info->chld_status);
+       (void)close(child_info->chld_status);
 }
 
 static void free_children(Children *children)
@@ -1445,11 +1445,11 @@ static void catch_input(gpointer data, gint source, GdkInputCondition cond)
        } while (c >= 0 && count < len);
 
        if (c >= 0)
-               write(child_info->chld_in, "\n", 2);
+               (void)write(child_info->chld_in, "\n", 2);
 
        g_free(input);
 
-       close(child_info->chld_in);
+       (void)close(child_info->chld_in);
        child_info->chld_in = -1;
        debug_print("Input to grand child sent.\n");
 }
@@ -1524,12 +1524,12 @@ static void catch_output(gpointer data, gint source, GdkInputCondition cond)
                if (source == child_info->chld_out) {
                        gdk_input_remove(child_info->tag_out);
                        child_info->tag_out = -1;
-                       close(child_info->chld_out);
+                       (void)close(child_info->chld_out);
                        child_info->chld_out = -1;
                } else {
                        gdk_input_remove(child_info->tag_err);
                        child_info->tag_err = -1;
-                       close(child_info->chld_err);
+                       (void)close(child_info->chld_err);
                        child_info->chld_err = -1;
                }
        }
index e2733b2..90f572e 100644 (file)
@@ -957,13 +957,18 @@ gint addrbook_read_data(AddressBookFile *book)
  * \param lvl  Indent level.
  * \param name Element name.
  */
-static void addrbook_write_elem_s(FILE *fp, gint lvl, gchar *name)
+static int addrbook_write_elem_s(FILE *fp, gint lvl, gchar *name)
 {
        gint i;
        for (i = 0; i < lvl; i++) 
-               fputs("  ", fp);
-       fputs("<", fp);
-       fputs(name, fp);
+               if (fputs("  ", fp) == EOF)
+                       return -1;
+       if (fputs("<", fp) == EOF)
+               return -1;
+       if (fputs(name, fp) == EOF)
+               return -1;
+               
+       return 0;
 }
 
 /**
@@ -972,14 +977,20 @@ static void addrbook_write_elem_s(FILE *fp, gint lvl, gchar *name)
  * \param lvl  Indent level.
  * \param name Element name.
  */
-static void addrbook_write_elem_e(FILE *fp, gint lvl, gchar *name)
+static int addrbook_write_elem_e(FILE *fp, gint lvl, gchar *name)
 {
        gint i;
        for(i = 0; i < lvl; i++)
-               fputs("  ", fp);
-       fputs("</", fp);
-       fputs(name, fp);
-       fputs(">\n", fp);
+               if (fputs("  ", fp) == EOF)
+                       return -1;
+       if (fputs("</", fp) == EOF)
+               return -1;
+       if (fputs(name, fp) == EOF)
+               return -1;
+       if (fputs(">\n", fp) == EOF)
+               return -1;
+               
+       return 0;
 }
 
 /**
@@ -988,15 +999,27 @@ static void addrbook_write_elem_e(FILE *fp, gint lvl, gchar *name)
  * \param name  Attribute name.
  * \param value Attribute value.
  */
-static void addrbook_write_attr(FILE *fp, gchar *name, gchar *value)
-{
-       fputs(" ", fp);
-       fputs(name, fp);
-       fputs("=\"", fp);
-       xml_file_put_escape_str(fp, value);
-       fputs("\"", fp);
+static int addrbook_write_attr(FILE *fp, gchar *name, gchar *value)
+{
+       if (fputs(" ", fp) == EOF)
+               return -1;
+       if (fputs(name, fp) == EOF)
+               return -1;
+       if (fputs("=\"", fp) == EOF)
+               return -1;
+       if (xml_file_put_escape_str(fp, value) < 0)
+               return -1;
+       if (fputs("\"", fp) == EOF)
+               return -1;
+       
+       return 0;
 }
 
+typedef struct _HashLoopData {
+       FILE *fp;
+       gboolean error;
+} HashLoopData;
+
 /**
  * Write person and associated addresses and attributes to file.
  * file hash table visitor function.
@@ -1005,10 +1028,11 @@ static void addrbook_write_attr(FILE *fp, gchar *name, gchar *value)
  * \param data  File pointer.
  */
 static void addrbook_write_item_person_vis(gpointer key, gpointer value, 
-                                          gpointer data)
+                                          gpointer d)
 {
        AddrItemObject *obj = (AddrItemObject *) value;
-       FILE *fp = (FILE *) data;
+       HashLoopData *data = (HashLoopData *)d;
+       FILE *fp = data->fp;
        GList *node;
 
        if (!obj)
@@ -1016,46 +1040,72 @@ static void addrbook_write_item_person_vis(gpointer key, gpointer value,
        if (ADDRITEM_TYPE(obj) == ITEMTYPE_PERSON) {
                ItemPerson *person = (ItemPerson *) value;
                if (person) {
-                       addrbook_write_elem_s(fp, 1, AB_ELTAG_PERSON);
-                       addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(person));
-                       addrbook_write_attr(fp, AB_ATTAG_FIRST_NAME, person->firstName);
-                       addrbook_write_attr(fp, AB_ATTAG_LAST_NAME, person->lastName);
-                       addrbook_write_attr(fp, AB_ATTAG_NICK_NAME, person->nickName);
-                       addrbook_write_attr(fp, AB_ATTAG_COMMON_NAME, ADDRITEM_NAME(person));
-                       fputs(" >\n", fp);
+                       if (addrbook_write_elem_s(fp, 1, AB_ELTAG_PERSON) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(person)) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_FIRST_NAME, person->firstName) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_LAST_NAME, person->lastName) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_NICK_NAME, person->nickName) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_COMMON_NAME, ADDRITEM_NAME(person)) < 0)
+                               data->error = TRUE;
+                       if (fputs(" >\n", fp) == EOF)
+                               data->error = TRUE;
 
                        /* Output email addresses */
-                       addrbook_write_elem_s(fp, 2, AB_ELTAG_ADDRESS_LIST);
-                       fputs(">\n", fp);
+                       if (addrbook_write_elem_s(fp, 2, AB_ELTAG_ADDRESS_LIST) < 0)
+                               data->error = TRUE;
+                       if (fputs(">\n", fp) == EOF)
+                               data->error = TRUE;
                        node = person->listEMail;
                        while (node) {
                                ItemEMail *email = node->data;
-                               addrbook_write_elem_s(fp, 3, AB_ELTAG_ADDRESS);
-                               addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(email));
-                               addrbook_write_attr(fp, AB_ATTAG_ALIAS, ADDRITEM_NAME(email));
-                               addrbook_write_attr(fp, AB_ATTAG_EMAIL, email->address);
-                               addrbook_write_attr(fp, AB_ATTAG_REMARKS, email->remarks);
-                               fputs(" />\n", fp);
+                               if (addrbook_write_elem_s(fp, 3, AB_ELTAG_ADDRESS) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(email)) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_ALIAS, ADDRITEM_NAME(email)) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_EMAIL, email->address) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_REMARKS, email->remarks) < 0)
+                                       data->error = TRUE;
+                               if (fputs(" />\n", fp) == EOF)
+                                       data->error = TRUE;
                                node = g_list_next(node);
                        }
-                       addrbook_write_elem_e(fp, 2, AB_ELTAG_ADDRESS_LIST);
+                       if (addrbook_write_elem_e(fp, 2, AB_ELTAG_ADDRESS_LIST) < 0)
+                               data->error = TRUE;
 
                        /* Output user attributes */
-                       addrbook_write_elem_s(fp, 2, AB_ELTAG_ATTRIBUTE_LIST);
-                       fputs(">\n", fp);
+                       if (addrbook_write_elem_s(fp, 2, AB_ELTAG_ATTRIBUTE_LIST) < 0)
+                               data->error = TRUE;
+                       if (fputs(">\n", fp) == EOF)
+                               data->error = TRUE;
                        node = person->listAttrib;
                        while (node) {
                                UserAttribute *attrib = node->data;
-                               addrbook_write_elem_s(fp, 3, AB_ELTAG_ATTRIBUTE);
-                               addrbook_write_attr(fp, AB_ATTAG_UID, attrib->uid);
-                               addrbook_write_attr(fp, AB_ATTAG_NAME, attrib->name);
-                               fputs(" >", fp);
-                               xml_file_put_escape_str(fp, attrib->value);
-                               addrbook_write_elem_e(fp, 0, AB_ELTAG_ATTRIBUTE);
+                               if (addrbook_write_elem_s(fp, 3, AB_ELTAG_ATTRIBUTE) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_UID, attrib->uid) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_NAME, attrib->name) < 0)
+                                       data->error = TRUE;
+                               if (fputs(" >", fp) == EOF)
+                                       data->error = TRUE;
+                               if (xml_file_put_escape_str(fp, attrib->value) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_elem_e(fp, 0, AB_ELTAG_ATTRIBUTE) < 0)
+                                       data->error = TRUE;
                                node = g_list_next(node);
                        }
-                       addrbook_write_elem_e(fp, 2, AB_ELTAG_ATTRIBUTE_LIST);
-                       addrbook_write_elem_e(fp, 1, AB_ELTAG_PERSON);
+                       if (addrbook_write_elem_e(fp, 2, AB_ELTAG_ATTRIBUTE_LIST) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_elem_e(fp, 1, AB_ELTAG_PERSON) < 0)
+                               data->error = TRUE;
                }
        }
 }
@@ -1068,10 +1118,12 @@ static void addrbook_write_item_person_vis(gpointer key, gpointer value,
  * \param data  File pointer.
  */
 static void addrbook_write_item_group_vis(gpointer key, gpointer value, 
-                                         gpointer data)
+                                         gpointer d)
 {
        AddrItemObject *obj = (AddrItemObject *) value;
-       FILE *fp = (FILE *) data;
+       HashLoopData *data = (HashLoopData *)d;
+       FILE *fp = data->fp;
+
        GList *node;
 
        if (!obj)
@@ -1079,27 +1131,40 @@ static void addrbook_write_item_group_vis(gpointer key, gpointer value,
        if (ADDRITEM_TYPE(obj) == ITEMTYPE_GROUP) {
                ItemGroup *group = (ItemGroup *) value;
                if (group) {
-                       addrbook_write_elem_s(fp, 1, AB_ELTAG_GROUP);
-                       addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(group));
-                       addrbook_write_attr(fp, AB_ATTAG_NAME, ADDRITEM_NAME(group));
-                       addrbook_write_attr(fp, AB_ATTAG_REMARKS, group->remarks);
-                       fputs(" >\n", fp);
+                       if (addrbook_write_elem_s(fp, 1, AB_ELTAG_GROUP) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(group)) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_NAME, ADDRITEM_NAME(group)) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_REMARKS, group->remarks) < 0)
+                               data->error = TRUE;
+                       if (fputs(" >\n", fp) == EOF)
+                               data->error = TRUE;
 
                        /* Output email address links */
-                       addrbook_write_elem_s(fp, 2, AB_ELTAG_MEMBER_LIST);
-                       fputs(">\n", fp);
+                       if (addrbook_write_elem_s(fp, 2, AB_ELTAG_MEMBER_LIST) < 0)
+                               data->error = TRUE;
+                       if (fputs(">\n", fp) == EOF)
+                               data->error = TRUE;
                        node = group->listEMail;
                        while (node) {
                                ItemEMail *email = node->data;
                                ItemPerson *person = (ItemPerson *) ADDRITEM_PARENT(email);
-                               addrbook_write_elem_s(fp, 3, AB_ELTAG_MEMBER);
-                               addrbook_write_attr(fp, AB_ATTAG_PID, ADDRITEM_ID(person));
-                               addrbook_write_attr(fp, AB_ATTAG_EID, ADDRITEM_ID(email));
-                               fputs(" />\n", fp);
+                               if (addrbook_write_elem_s(fp, 3, AB_ELTAG_MEMBER) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_PID, ADDRITEM_ID(person)) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_EID, ADDRITEM_ID(email)) < 0)
+                                       data->error = TRUE;
+                               if (fputs(" />\n", fp) == EOF)
+                                       data->error = TRUE;
                                node = g_list_next(node);
                        }
-                       addrbook_write_elem_e(fp, 2, AB_ELTAG_MEMBER_LIST);
-                       addrbook_write_elem_e(fp, 1, AB_ELTAG_GROUP);
+                       if (addrbook_write_elem_e(fp, 2, AB_ELTAG_MEMBER_LIST) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_elem_e(fp, 1, AB_ELTAG_GROUP) < 0)
+                               data->error = TRUE;
                }
        }
 }
@@ -1112,10 +1177,11 @@ static void addrbook_write_item_group_vis(gpointer key, gpointer value,
  * \param data  File pointer.
  */
 static void addrbook_write_item_folder_vis(gpointer key, gpointer value, 
-                                          gpointer data)
+                                          gpointer d)
 {
        AddrItemObject *obj = (AddrItemObject *) value;
-       FILE *fp = (FILE *) data;
+       HashLoopData *data = (HashLoopData *)d;
+       FILE *fp = data->fp;
        GList *node;
 
        if (!obj)
@@ -1123,22 +1189,33 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
        if (ADDRITEM_TYPE(obj) == ITEMTYPE_FOLDER) {
                ItemFolder *folder = (ItemFolder *) value;
                if (folder) {
-                       addrbook_write_elem_s(fp, 1, AB_ELTAG_FOLDER);
-                       addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(folder));
-                       addrbook_write_attr(fp, AB_ATTAG_NAME, ADDRITEM_NAME(folder));
-                       addrbook_write_attr(fp, AB_ATTAG_REMARKS, folder->remarks);
-                       fputs(" >\n", fp);
-                       addrbook_write_elem_s(fp, 2, AB_ELTAG_ITEM_LIST);
-                       fputs(">\n", fp);
+                       if (addrbook_write_elem_s(fp, 1, AB_ELTAG_FOLDER) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(folder)) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_NAME, ADDRITEM_NAME(folder)) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_attr(fp, AB_ATTAG_REMARKS, folder->remarks) < 0)
+                               data->error = TRUE;
+                       if (fputs(" >\n", fp) == EOF)
+                               data->error = TRUE;
+                       if (addrbook_write_elem_s(fp, 2, AB_ELTAG_ITEM_LIST) < 0)
+                               data->error = TRUE;
+                       if (fputs(">\n", fp) == EOF)
+                               data->error = TRUE;
 
                        /* Output persons */
                        node = folder->listPerson;
                        while (node) {
                                ItemPerson *item = node->data;
-                               addrbook_write_elem_s(fp, 3, AB_ELTAG_ITEM);
-                               addrbook_write_attr(fp, AB_ATTAG_TYPE,  AB_ATTAG_VAL_PERSON);
-                               addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item));
-                               fputs(" />\n", fp);
+                               if (addrbook_write_elem_s(fp, 3, AB_ELTAG_ITEM) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_TYPE,  AB_ATTAG_VAL_PERSON) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item)) < 0)
+                                       data->error = TRUE;
+                               if (fputs(" />\n", fp) == EOF)
+                                       data->error = TRUE;
                                node = g_list_next(node);
                        }
 
@@ -1146,10 +1223,14 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
                        node = folder->listGroup;
                        while (node) {
                                ItemGroup *item = node->data;
-                               addrbook_write_elem_s(fp, 3, AB_ELTAG_ITEM);
-                               addrbook_write_attr(fp, AB_ATTAG_TYPE, AB_ATTAG_VAL_GROUP);
-                               addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item));
-                               fputs(" />\n", fp);
+                               if (addrbook_write_elem_s(fp, 3, AB_ELTAG_ITEM) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_TYPE, AB_ATTAG_VAL_GROUP) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item)) < 0)
+                                       data->error = TRUE;
+                               if (fputs(" />\n", fp) == EOF)
+                                       data->error = TRUE;
                                node = g_list_next(node);
                        }
 
@@ -1157,14 +1238,20 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
                        node = folder->listFolder;
                        while (node) {
                                ItemFolder *item = node->data;
-                               addrbook_write_elem_s(fp, 3, AB_ELTAG_ITEM);
-                               addrbook_write_attr(fp, AB_ATTAG_TYPE, AB_ATTAG_VAL_FOLDER);
-                               addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item));
-                               fputs(" />\n", fp);
+                               if (addrbook_write_elem_s(fp, 3, AB_ELTAG_ITEM) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_TYPE, AB_ATTAG_VAL_FOLDER) < 0)
+                                       data->error = TRUE;
+                               if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item)) < 0)
+                                       data->error = TRUE;
+                               if (fputs(" />\n", fp) == EOF)
+                                       data->error = TRUE;
                                node = g_list_next(node);
                        }
-                       addrbook_write_elem_e(fp, 2, AB_ELTAG_ITEM_LIST);
-                       addrbook_write_elem_e(fp, 1, AB_ELTAG_FOLDER);
+                       if (addrbook_write_elem_e(fp, 2, AB_ELTAG_ITEM_LIST) < 0)
+                               data->error = TRUE;
+                       if (addrbook_write_elem_e(fp, 1, AB_ELTAG_FOLDER) < 0)
+                               data->error = TRUE;
                }
        }
 }
@@ -1179,6 +1266,7 @@ static gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 {
        FILE *fp;
        gchar *fileSpec;
+       HashLoopData data;
 #ifndef DEV_STANDALONE
        PrefFile *pfile;
 #endif
@@ -1193,32 +1281,52 @@ static gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
        fp = g_fopen(fileSpec, "wb");
        g_free(fileSpec);
        if (fp) {
-               fputs("<?xml version=\"1.0\" ?>\n", fp);
+               if (fputs("<?xml version=\"1.0\" ?>\n", fp) == EOF) {
+                       book->retVal = MGU_ERROR_WRITE;
+                       return book->retVal;
+               }
 #else
        pfile = prefs_write_open(fileSpec);
        g_free(fileSpec);
        if (pfile) {
                fp = pfile->fp;
-               fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL );
+               if (fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL ) < 0)
+                       goto fail;
 #endif
-               addrbook_write_elem_s(fp, 0, AB_ELTAG_ADDRESS_BOOK);
-               addrbook_write_attr(fp, AB_ATTAG_NAME,
-                                   addrcache_get_name(book->addressCache));
-               fputs(" >\n", fp);
+               if (addrbook_write_elem_s(fp, 0, AB_ELTAG_ADDRESS_BOOK) < 0)
+                       goto fail;
+               if (addrbook_write_attr(fp, AB_ATTAG_NAME,
+                                   addrcache_get_name(book->addressCache)) < 0)
+                       goto fail;
+               if (fputs(" >\n", fp) == EOF)
+                       goto fail;
 
                /* Output all persons */
+               data.fp = fp;
+               data.error = FALSE;
+
                g_hash_table_foreach(book->addressCache->itemHash, 
-                                    addrbook_write_item_person_vis, fp);
+                                    addrbook_write_item_person_vis, &data);
+               if (data.error)
+                       goto fail;
 
                /* Output all groups */
                g_hash_table_foreach(book->addressCache->itemHash, 
-                                    addrbook_write_item_group_vis, fp);
+                                    addrbook_write_item_group_vis, &data);
+
+               if (data.error)
+                       goto fail;
 
                /* Output all folders */
                g_hash_table_foreach(book->addressCache->itemHash, 
-                                    addrbook_write_item_folder_vis, fp);
+                                    addrbook_write_item_folder_vis, &data);
+
+               if (data.error)
+                       goto fail;
+
+               if (addrbook_write_elem_e(fp, 0, AB_ELTAG_ADDRESS_BOOK) < 0)
+                       goto fail;
 
-               addrbook_write_elem_e(fp, 0, AB_ELTAG_ADDRESS_BOOK);
                book->retVal = MGU_SUCCESS;
 #ifdef DEV_STANDALONE
                fclose(fp);
@@ -1230,6 +1338,12 @@ static gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 
        fileSpec = NULL;
        return book->retVal;
+fail:
+       g_warning("error writing AB\n");
+       book->retVal = MGU_ERROR_WRITE;
+       if (pfile)
+               prefs_file_close_revert( pfile );
+       return book->retVal;
 }
 
 /**
index ea3aeb9..433a736 100644 (file)
@@ -927,11 +927,16 @@ static AddressInterface *addrindex_tag_get_datasource(
  * \param lvl  Indentation level.
  * \param name Element name.
  */
-static void addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) {
+static int addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) {
        gint i;
-       for( i = 0; i < lvl; i++ ) fputs( "  ", fp );
-       fputs( "<", fp );
-       fputs( name, fp );
+       for( i = 0; i < lvl; i++ ) 
+               if (fputs( "  ", fp ) == EOF)
+                       return -1;
+       if (fputs( "<", fp ) == EOF)
+               return -1;
+       if (fputs( name, fp ) == EOF)
+               return -1;
+       return 0;
 }
 
 /**
@@ -940,12 +945,18 @@ static void addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name
  * \param lvl  Indentation level.
  * \param name Element name.
  */
-static void addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name ) {
+static int addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name ) {
        gint i;
-       for( i = 0; i < lvl; i++ ) fputs( "  ", fp );
-       fputs( "</", fp );
-       fputs( name, fp );
-       fputs( ">\n", fp );
+       for( i = 0; i < lvl; i++ ) 
+               if (fputs( "  ", fp ) == EOF)
+                       return -1;
+       if (fputs( "</", fp ) == EOF)
+               return -1;
+       if (fputs( name, fp ) == EOF)
+               return -1;
+       if (fputs( ">\n", fp ) == EOF)
+               return -1;
+       return 0;
 }
 
 /**
@@ -954,12 +965,18 @@ static void addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name
  * \param name  Attribute name.
  * \param value Attribute value.
  */
-static void addrindex_write_attr( FILE *fp, const gchar *name, const gchar *value ) {
-       fputs( " ", fp );
-       fputs( name, fp );
-       fputs( "=\"", fp );
-       xml_file_put_escape_str( fp, value );
-       fputs( "\"", fp );
+static int addrindex_write_attr( FILE *fp, const gchar *name, const gchar *value ) {
+       if (fputs( " ", fp ) == EOF)
+               return -1;
+       if (fputs( name, fp ) == EOF)
+               return -1;
+       if (fputs( "=\"", fp ) == EOF)
+               return -1;
+       if (xml_file_put_escape_str( fp, value ) < 0)
+               return -1;
+       if (fputs( "\"", fp ) == EOF)
+               return -1;
+       return 0;
 }
 
 /**
@@ -1030,37 +1047,45 @@ static AddressIfFragment *addrindex_read_fragment( XMLFile *file ) {
  * \param fragment DOM fragment for configuration element.
  * \param lvl      Indent level.
  */
-static void addrindex_write_fragment(
+static int addrindex_write_fragment(
                FILE *fp, const AddressIfFragment *fragment, const gint lvl )
 {
        GList *node;
 
        if( fragment ) {
-               addrindex_write_elem_s( fp, lvl, fragment->name );
+               if (addrindex_write_elem_s( fp, lvl, fragment->name ) < 0)
+                       return -1;
                node = fragment->attributes;
                while( node ) {
                        AddressIfAttrib *nv = node->data;
-                       addrindex_write_attr( fp, nv->name, nv->value );
+                       if (addrindex_write_attr( fp, nv->name, nv->value ) < 0)
+                               return -1;
                        node = g_list_next( node );
                }
                if( fragment->children ) {
-                       fputs(" >\n", fp);
+                       if (fputs(" >\n", fp) == EOF)
+                               return -1;
 
                        /* Output children */
                        node = fragment->children;
                        while( node ) {
                                AddressIfFragment *child = node->data;
-                               addrindex_write_fragment( fp, child, 1+lvl );
+                               if (addrindex_write_fragment( fp, child, 1+lvl ) < 0)
+                                       return -1;
                                node = g_list_next( node );
                        }
 
                        /* Output closing tag */
-                       addrindex_write_elem_e( fp, lvl, fragment->name );
+                       if (addrindex_write_elem_e( fp, lvl, fragment->name ) < 0)
+                               return -1;
                }
                else {
-                       fputs(" />\n", fp);
+                       if (fputs(" />\n", fp) == EOF)
+                               return -1;
                }
        }
+       
+       return 0;
 }
 
 /**
@@ -1092,14 +1117,19 @@ static AddressDataSource *addrindex_parse_book( XMLFile *file ) {
        return ds;
 }
 
-static void addrindex_write_book( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_book( FILE *fp, AddressDataSource *ds, gint lvl ) {
        AddressBookFile *abf = ds->rawDataSource;
        if( abf ) {
-               addrindex_write_elem_s( fp, lvl, TAG_DS_ADDRESS_BOOK );
-               addrindex_write_attr( fp, ATTAG_BOOK_NAME, addrbook_get_name( abf ) );
-               addrindex_write_attr( fp, ATTAG_BOOK_FILE, abf->fileName );
-               fputs( " />\n", fp );
+               if (addrindex_write_elem_s( fp, lvl, TAG_DS_ADDRESS_BOOK ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_BOOK_NAME, addrbook_get_name( abf ) ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_BOOK_FILE, abf->fileName ) < 0)
+                       return -1;
+               if (fputs( " />\n", fp ) == EOF)
+                       return -1;
        }
+       return 0;
 }
 
 static AddressDataSource *addrindex_parse_vcard( XMLFile *file ) {
@@ -1125,14 +1155,19 @@ static AddressDataSource *addrindex_parse_vcard( XMLFile *file ) {
        return ds;
 }
 
-static void addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) {
        VCardFile *vcf = ds->rawDataSource;
        if( vcf ) {
-               addrindex_write_elem_s( fp, lvl, TAG_DS_VCARD );
-               addrindex_write_attr( fp, ATTAG_VCARD_NAME, vcard_get_name( vcf ) );
-               addrindex_write_attr( fp, ATTAG_VCARD_FILE, vcf->path );
-               fputs( " />\n", fp );
+               if (addrindex_write_elem_s( fp, lvl, TAG_DS_VCARD ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_VCARD_NAME, vcard_get_name( vcf ) ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_VCARD_FILE, vcf->path ) < 0)
+                       return -1;
+               if (fputs( " />\n", fp ) == EOF)
+                       return -1;
        }
+       return 0;
 }
 
 #ifdef USE_JPILOT
@@ -1171,27 +1206,33 @@ static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) {
        return ds;
 }
 
-static void addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) {
        JPilotFile *jpf = ds->rawDataSource;
        if( jpf ) {
                gint ind;
                GList *node;
                GList *customLbl = jpilot_get_custom_labels( jpf );
-               addrindex_write_elem_s( fp, lvl, TAG_DS_JPILOT );
-               addrindex_write_attr( fp, ATTAG_JPILOT_NAME, jpilot_get_name( jpf ) );
-               addrindex_write_attr( fp, ATTAG_JPILOT_FILE, jpf->path );
+               if (addrindex_write_elem_s( fp, lvl, TAG_DS_JPILOT ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_JPILOT_NAME, jpilot_get_name( jpf ) ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_JPILOT_FILE, jpf->path ) < 0)
+                       return -1;
                node = customLbl;
                ind = 1;
                while( node ) {
                        gchar name[256];
                        g_snprintf( name, sizeof(name), "%s%d",
                                    ATTAG_JPILOT_CUSTOM, ind );
-                       addrindex_write_attr( fp, name, node->data );
+                       if (addrindex_write_attr( fp, name, node->data ) < 0)
+                               return -1;
                        ind++;
                        node = g_list_next( node );
                }
-               fputs( " />\n", fp );
+               if (fputs( " />\n", fp ) == EOF)
+                       return -1;
        }
+       return 0;
 }
 
 #else
@@ -1206,11 +1247,13 @@ static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) {
        return ds;
 }
 
-static void addrindex_write_jpilot( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_jpilot( FILE *fp, AddressDataSource *ds, gint lvl ) {
        AddressIfFragment *fragment = ds->rawDataSource;
        if( fragment ) {
-               addrindex_write_fragment( fp, fragment, lvl );
+               if (addrindex_write_fragment( fp, fragment, lvl ) < 0)
+                       return -1;
        }
+       return 0;
 }
 #endif
 
@@ -1410,7 +1453,7 @@ static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
        return ds;
 }
 
-static void addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
        LdapServer *server = ds->rawDataSource;
        LdapControl *ctl = NULL;
        GList *node;
@@ -1419,55 +1462,76 @@ static void addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
        if( server ) {
                ctl = server->control;
        }
-       if( ctl == NULL ) return;
+       if( ctl == NULL ) return 0;
 
        /* Output start element with attributes */
-       addrindex_write_elem_s( fp, lvl, TAG_DS_LDAP );
-       addrindex_write_attr( fp, ATTAG_LDAP_NAME, ldapsvr_get_name( server ) );
-       addrindex_write_attr( fp, ATTAG_LDAP_HOST, ctl->hostName );
+       if (addrindex_write_elem_s( fp, lvl, TAG_DS_LDAP ) < 0)
+               return -1;
+       if (addrindex_write_attr( fp, ATTAG_LDAP_NAME, ldapsvr_get_name( server ) ) < 0)
+               return -1;
+       if (addrindex_write_attr( fp, ATTAG_LDAP_HOST, ctl->hostName ) < 0)
+               return -1;
 
        sprintf( value, "%d", ctl->port );      
-       addrindex_write_attr( fp, ATTAG_LDAP_PORT, value );
+       if (addrindex_write_attr( fp, ATTAG_LDAP_PORT, value ) < 0)
+               return -1;
 
-       addrindex_write_attr( fp, ATTAG_LDAP_BASE_DN, ctl->baseDN );
-       addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, ctl->bindDN );
-       addrindex_write_attr( fp, ATTAG_LDAP_BIND_PASS, ctl->bindPass );
+       if (addrindex_write_attr( fp, ATTAG_LDAP_BASE_DN, ctl->baseDN ) < 0)
+               return -1;
+       if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, ctl->bindDN ) < 0)
+               return -1;
+       if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_PASS, ctl->bindPass ) < 0)
+               return -1;
 
        sprintf( value, "%d", ctl->maxEntries );
-       addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value );
+       if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value ) < 0)
+               return -1;
        sprintf( value, "%d", ctl->timeOut );
-       addrindex_write_attr( fp, ATTAG_LDAP_TIMEOUT, value );
+       if (addrindex_write_attr( fp, ATTAG_LDAP_TIMEOUT, value ) < 0)
+               return -1;
        sprintf( value, "%d", ctl->maxQueryAge );
-       addrindex_write_attr( fp, ATTAG_LDAP_MAX_AGE, value );
+       if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_AGE, value ) < 0)
+               return -1;
 
-       addrindex_write_attr( fp, ATTAG_LDAP_DYN_SEARCH,
+       if (addrindex_write_attr( fp, ATTAG_LDAP_DYN_SEARCH,
                        server->searchFlag ?
-                       ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO );
+                       ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
+               return -1;
 
-       addrindex_write_attr( fp, ATTAG_LDAP_MATCH_OPT,
+       if (addrindex_write_attr( fp, ATTAG_LDAP_MATCH_OPT,
                ( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) ?
-               ATVAL_LDAP_MATCH_CONTAINS : ATVAL_LDAP_MATCH_BEGIN );
+               ATVAL_LDAP_MATCH_CONTAINS : ATVAL_LDAP_MATCH_BEGIN ) < 0)
+               return -1;
 
-       addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_TLS,
+       if (addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_TLS,
                        ctl->enableTLS ?
-                       ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO );
-       addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_SSL,
+                       ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
+               return -1;
+       if (addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_SSL,
                        ctl->enableSSL ?
-                       ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO );
+                       ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
+               return -1;
 
-       fputs(" >\n", fp);
+       if (fputs(" >\n", fp) == EOF)
+               return -1;
 
        /* Output attributes */
        node = ldapctl_get_criteria_list( ctl );
        while( node ) {
-               addrindex_write_elem_s( fp, 1+lvl, ELTAG_LDAP_ATTR_SRCH );
-               addrindex_write_attr( fp, ATTAG_LDAP_ATTR_NAME, node->data );
-               fputs(" />\n", fp);
+               if (addrindex_write_elem_s( fp, 1+lvl, ELTAG_LDAP_ATTR_SRCH ) < 0)
+                       return -1;
+               if (addrindex_write_attr( fp, ATTAG_LDAP_ATTR_NAME, node->data ) < 0)
+                       return -1;
+               if (fputs(" />\n", fp) == EOF)
+                       return -1;
                node = g_list_next( node );
        }
 
        /* End of element */    
-       addrindex_write_elem_e( fp, lvl, TAG_DS_LDAP );
+       if (addrindex_write_elem_e( fp, lvl, TAG_DS_LDAP ) < 0)
+               return -1;
+       
+       return 0;
 }
 
 #else
@@ -1482,11 +1546,13 @@ static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
        return ds;
 }
 
-static void addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
+static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
        AddressIfFragment *fragment = ds->rawDataSource;
        if( fragment ) {
-               addrindex_write_fragment( fp, fragment, lvl );
+               if (addrindex_write_fragment( fp, fragment, lvl ) < 0)
+                       return -1;
        }
+       return 0;
 }
 #endif
 
@@ -1625,7 +1691,7 @@ static gint addrindex_read_file( AddressIndex *addrIndex ) {
        return addrIndex->retVal;
 }
 
-static void addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) {
+static int addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) {
        GList *nodeIF, *nodeDS;
        gint lvlList = 1;
        gint lvlItem = 1 + lvlList;
@@ -1635,30 +1701,38 @@ static void addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) {
                AddressInterface *iface = nodeIF->data;
                if( ! iface->legacyFlag ) {
                        nodeDS = iface->listSource;
-                       addrindex_write_elem_s( fp, lvlList, iface->listTag );
-                       fputs( ">\n", fp );
+                       if (addrindex_write_elem_s( fp, lvlList, iface->listTag ) < 0)
+                               return -1;
+                       if (fputs( ">\n", fp ) == EOF)
+                               return -1;
                        while( nodeDS ) {
                                AddressDataSource *ds = nodeDS->data;
                                if( ds ) {
                                        if( iface->type == ADDR_IF_BOOK ) {
-                                               addrindex_write_book( fp, ds, lvlItem );
+                                               if (addrindex_write_book( fp, ds, lvlItem ) < 0)
+                                                       return -1;
                                        }
                                        if( iface->type == ADDR_IF_VCARD ) {
-                                               addrindex_write_vcard( fp, ds, lvlItem );
+                                               if (addrindex_write_vcard( fp, ds, lvlItem ) < 0)
+                                                       return -1;
                                        }
                                        if( iface->type == ADDR_IF_JPILOT ) {
-                                               addrindex_write_jpilot( fp, ds, lvlItem );
+                                               if (addrindex_write_jpilot( fp, ds, lvlItem ) < 0)
+                                                       return -1;
                                        }
                                        if( iface->type == ADDR_IF_LDAP ) {
-                                               addrindex_write_ldap( fp, ds, lvlItem );
+                                               if (addrindex_write_ldap( fp, ds, lvlItem ) < 0)
+                                                       return -1;
                                        }
                                }
                                nodeDS = g_list_next( nodeDS );
                        }
-                       addrindex_write_elem_e( fp, lvlList, iface->listTag );
+                       if (addrindex_write_elem_e( fp, lvlList, iface->listTag ) < 0)
+                               return -1;
                }
                nodeIF = g_list_next( nodeIF );
        }
+       return 0;
 }
 
 /*
@@ -1689,13 +1763,18 @@ static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile )
        g_free( fileSpec );
        if( pfile ) {
                fp = pfile->fp;
-               fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL );
+               if (fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL ) < 0)
+                       goto fail;
 #endif
-               addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX );
-               fputs( ">\n", fp );
+               if (addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX ) < 0)
+                       goto fail;
+               if (fputs( ">\n", fp ) == EOF)
+                       goto fail;
 
-               addrindex_write_index( addrIndex, fp );
-               addrindex_write_elem_e( fp, 0, TAG_ADDRESS_INDEX );
+               if (addrindex_write_index( addrIndex, fp ) < 0)
+                       goto fail;
+               if (addrindex_write_elem_e( fp, 0, TAG_ADDRESS_INDEX ) < 0)
+                       goto fail;
 
                addrIndex->retVal = MGU_SUCCESS;
 #ifdef DEV_STANDALONE
@@ -1709,6 +1788,12 @@ static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile )
 
        fileSpec = NULL;
        return addrIndex->retVal;
+fail:
+       g_warning("error writing AB index\n");
+       addrIndex->retVal = MGU_ERROR_WRITE;
+       if (pfile)
+               prefs_file_close_revert( pfile );
+       return addrIndex->retVal;
 }
 
 /*
index e53287c..1953d07 100644 (file)
@@ -149,8 +149,9 @@ void log_print(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_standard()) {
-               fputs(buf, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fputs(buf, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
 
@@ -178,10 +179,11 @@ void log_message(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_standard()) {
-               fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
-               fputs("* message: ", log_fp[instance]);
-               fputs(buf + LOG_TIME_LEN, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
+               r = fputs("* message: ", log_fp[instance]);
+               r = fputs(buf + LOG_TIME_LEN, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
 
@@ -209,10 +211,11 @@ void log_warning(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_warning()) {
-               fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
-               fputs("** warning: ", log_fp[instance]);
-               fputs(buf + LOG_TIME_LEN, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
+               r = fputs("** warning: ", log_fp[instance]);
+               r = fputs(buf + LOG_TIME_LEN, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
 
@@ -240,10 +243,11 @@ void log_error(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_error()) {
-               fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
-               fputs("*** error: ", log_fp[instance]);
-               fputs(buf + LOG_TIME_LEN, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
+               r = fputs("*** error: ", log_fp[instance]);
+               r = fputs(buf + LOG_TIME_LEN, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
 
@@ -271,10 +275,11 @@ void log_status_ok(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_status()) {
-               fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
-               fputs("* OK: ", log_fp[instance]);
-               fputs(buf + LOG_TIME_LEN, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
+               r = fputs("* OK: ", log_fp[instance]);
+               r = fputs(buf + LOG_TIME_LEN, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
 
@@ -302,10 +307,11 @@ void log_status_nok(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_status()) {
-               fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
-               fputs("* NOT OK: ", log_fp[instance]);
-               fputs(buf + LOG_TIME_LEN, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
+               r = fputs("* NOT OK: ", log_fp[instance]);
+               r = fputs(buf + LOG_TIME_LEN, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
 
@@ -333,9 +339,10 @@ void log_status_skip(LogInstance instance, const gchar *format, ...)
        g_timeout_add(0, invoke_hook_cb, logtext);
 
        if (log_fp[instance] && prefs_common_enable_log_status()) {
-               fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
-               fputs("* SKIPPED: ", log_fp[instance]);
-               fputs(buf + LOG_TIME_LEN, log_fp[instance]);
-               fflush(log_fp[instance]);
+               int r;
+               r = fwrite(buf, 1, LOG_TIME_LEN, log_fp[instance]);
+               r = fputs("* SKIPPED: ", log_fp[instance]);
+               r = fputs(buf + LOG_TIME_LEN, log_fp[instance]);
+               r = fflush(log_fp[instance]);
        }
 }
index fe3548f..a2a9186 100644 (file)
@@ -34,7 +34,7 @@
 void mgu_print_list( GSList *list, FILE *stream ) {
        GSList *node = list;
        while( node ) {
-               fprintf( stream, "\t- >%s<\n", (gchar *)node->data );
+               int r = fprintf( stream, "\t- >%s<\n", (gchar *)node->data );
                node = g_slist_next( node );
        }
 }
@@ -45,7 +45,7 @@ void mgu_print_list( GSList *list, FILE *stream ) {
 void mgu_print_dlist( GList *list, FILE *stream ) {
        GList *node = list;
        while( node ) {
-               fprintf( stream, "\t- >%s<\n", (gchar *)node->data );
+               int r = fprintf( stream, "\t- >%s<\n", (gchar *)node->data );
                node = g_list_next( node );
        }
 }
index 20f942e..72cf087 100644 (file)
@@ -101,7 +101,7 @@ void plugin_save_list(void)
        PrefFile *pfile;
        GSList *type_cur, *plugin_cur;
        Plugin *plugin;
-
+       
        for (type_cur = plugin_types; type_cur != NULL; type_cur = g_slist_next(type_cur)) {
                rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
 #ifdef G_OS_WIN32
@@ -124,7 +124,8 @@ void plugin_save_list(void)
                                continue;
 
                        if (!strcmp(plugin->type(), type_cur->data))
-                               fprintf(pfile->fp, "%s\n", plugin->filename);
+                               if (fprintf(pfile->fp, "%s\n", plugin->filename) < 0)
+                                       goto revert;
                }
                for (plugin_cur = unloaded_plugins; plugin_cur != NULL; plugin_cur = g_slist_next(plugin_cur)) {
                        plugin = (Plugin *) plugin_cur->data;
@@ -133,14 +134,25 @@ void plugin_save_list(void)
                                continue;
                        
                        if (!strcmp(plugin->type(), type_cur->data))
-                               fprintf(pfile->fp, "%s\n", plugin->filename);
+                               if (fprintf(pfile->fp, "%s\n", plugin->filename) < 0)
+                                       goto revert;
                }
-               fprintf(pfile->fp, "\n");
+               if (fprintf(pfile->fp, "\n") < 0)
+                       goto revert;
 
                if (prefs_file_close(pfile) < 0)
                        g_warning("failed to write plugin list\n");
 
                g_free(rcpath); 
+               
+               return;
+
+revert:
+               g_warning("failed to write plugin list\n");
+               if (prefs_file_close_revert(pfile) < 0)
+                       g_warning("failed to revert plugin list\n");
+
+               g_free(rcpath); 
        }
 }
 
index f620d34..f00a4ec 100644 (file)
@@ -4849,6 +4849,7 @@ void mailcap_update_default(const gchar *type, const gchar *command)
        FILE *fp = fopen(path, "rb");
        FILE *outfp = fopen(outpath, "wb");
        gchar buf[BUFFSIZE];
+       gboolean err = FALSE;
 
        if (!outfp) {
                g_free(path);
@@ -4869,17 +4870,27 @@ void mailcap_update_default(const gchar *type, const gchar *command)
                        continue;
                }
                else {
-                       fputs(buf, outfp);
+                       if(fputs(buf, outfp) == EOF) {
+                               err = TRUE;
+                               break;
+                       }
                }
                g_strfreev(parts);
        }
-       fprintf(outfp, "%s; %s\n", type, command);
+       if (fprintf(outfp, "%s; %s\n", type, command) < 0)
+               err = TRUE;
 
        if (fp)
                fclose(fp);
 
-       fclose(outfp);
-       g_rename(outpath, path);
+       if (fclose(outfp) == EOF)
+               err = TRUE;
+               
+       if (!err)
+               g_rename(outpath, path);
+
+       g_free(path);
+       g_free(outpath);
 }
 
 gint copy_dir(const gchar *src, const gchar *dst)
index d776337..9027c44 100644 (file)
@@ -596,33 +596,6 @@ gint xml_file_put_xml_decl(FILE *fp)
        return fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", CS_INTERNAL);
 }
 
-gint xml_file_put_node(FILE *fp, XMLNode *node)
-{
-       GList *cur;
-
-       g_return_val_if_fail(fp != NULL, -1);
-       g_return_val_if_fail(node != NULL, -1);
-
-       fprintf(fp, "<%s", node->tag->tag);
-
-       for (cur = node->tag->attr; cur != NULL; cur = cur->next) {
-               XMLAttr *attr = (XMLAttr *)cur->data;
-               fprintf(fp, " %s=\"", attr->name);
-               xml_file_put_escape_str(fp, attr->value);
-               fputs("\"", fp);
-       }
-
-       if (node->element) {
-               fputs(">", fp);
-               xml_file_put_escape_str(fp, node->element);
-               fprintf(fp, "</%s>\n", node->tag->tag);
-       } else {
-               fputs(" />\n", fp);
-       }
-
-       return 0;
-}
-
 void xml_free_node(XMLNode *node)
 {
        if (!node) return;
@@ -724,7 +697,7 @@ static int xml_write_tree_recursive(GNode *node, FILE *fp)
 
        if (node->children) {
                GNode *child;
-               fputs(">\n", fp);
+               TRY(fputs(">\n", fp) != EOF);
 
                child = node->children;
                while (child) {
index 2dd2b33..226e959 100644 (file)
@@ -103,8 +103,6 @@ gint xml_file_put_escape_str        (FILE           *fp,
                                 const gchar    *str);
 
 gint xml_file_put_xml_decl     (FILE           *fp);
-gint xml_file_put_node         (FILE           *fp,
-                                XMLNode        *node);
 
 void xml_free_node             (XMLNode        *node);
 void xml_free_tree             (GNode          *node);
index 149e885..2bf941c 100644 (file)
 #define XMLS_ATTAG_NAME          "name"
 #define XMLS_ATTAG_VALUE         "value"
 
+typedef struct _HashLoopData {
+       FILE *fp;
+       int error;
+} HashLoopData;
+
 /*
  * Create new props.
  */
@@ -119,64 +124,110 @@ void xmlprops_free( XmlProperty *props ) {
        g_free( props );
 }
 
-static void xmlprops_write_elem_s( FILE *fp, gint lvl, gchar *name ) {
+static int xmlprops_write_elem_s( FILE *fp, gint lvl, gchar *name ) {
        gint i;
-       for( i = 0; i < lvl; i++ ) fputs( "  ", fp );
-       fputs( "<", fp );
-       fputs( name, fp );
+       for( i = 0; i < lvl; i++ ) {
+               if(fputs( "  ", fp ) == EOF)
+                       return -1;
+       }
+       if(fputs( "<", fp ) == EOF)
+               return -1;
+       if(fputs( name, fp ) == EOF)
+               return -1;
+       
+       return 0;
 }
 
-static void xmlprops_write_elem_e( FILE *fp, gint lvl, gchar *name ) {
+static int xmlprops_write_elem_e( FILE *fp, gint lvl, gchar *name ) {
        gint i;
-       for( i = 0; i < lvl; i++ ) fputs( "  ", fp );
-       fputs( "</", fp );
-       fputs( name, fp );
-       fputs( ">\n", fp );
+       for( i = 0; i < lvl; i++ ) {
+               if(fputs( "  ", fp ) == EOF)
+                       return -1;
+       }
+       if(fputs( "</", fp ) == EOF)
+               return -1;
+       if(fputs( name, fp ) == EOF)
+               return -1;
+       if(fputs( ">\n", fp ) == EOF)
+               return -1;
+       
+       return 0;
 }
 
-static void xmlprops_write_attr( FILE *fp, gchar *name, gchar *value ) {
-       fputs( " ", fp );
-       fputs( name, fp );
-       fputs( "=\"", fp );
-       xml_file_put_escape_str( fp, value );
-       fputs( "\"", fp );
+static int xmlprops_write_attr( FILE *fp, gchar *name, gchar *value ) {
+       if(fputs( " ", fp ) == EOF)
+               return -1;
+       if(fputs( name, fp ) == EOF)
+               return -1;
+       if(fputs( "=\"", fp ) == EOF)
+               return -1;
+       if(xml_file_put_escape_str( fp, value ) < 0)
+               return -1;
+       if(fputs( "\"", fp ) == EOF)
+               return -1;
+       
+       return 0;
 }
 
-static void xmlprops_write_vis( gpointer key, gpointer value, gpointer data ) {
-       FILE *fp = ( FILE * ) data;
-
-       xmlprops_write_elem_s( fp, 1, XMLS_ELTAG_PROPERTY );
-       xmlprops_write_attr( fp, XMLS_ATTAG_NAME, key );
-       xmlprops_write_attr( fp, XMLS_ATTAG_VALUE, value );
-       fputs( " />\n", fp );
+static void xmlprops_write_vis( gpointer key, gpointer value, gpointer d ) {
+       HashLoopData *data = (HashLoopData *)d;
+
+       if(xmlprops_write_elem_s( data->fp, 1, XMLS_ELTAG_PROPERTY ) < 0)
+               data->error = 1;
+       if(xmlprops_write_attr( data->fp, XMLS_ATTAG_NAME, key ) < 0)
+               data->error = 1;
+       if(xmlprops_write_attr( data->fp, XMLS_ATTAG_VALUE, value ) < 0)
+               data->error = 1;
+       if(fputs( " />\n", data->fp ) == EOF)
+               data->error = 1;
 }
 
 static gint xmlprops_write_to( XmlProperty *props, const gchar *fileSpec ) {
        PrefFile *pfile;
        FILE *fp;
+       HashLoopData data;
 
        props->retVal = MGU_OPEN_FILE;
        pfile = prefs_write_open( fileSpec );
        if( pfile ) {
                fp = pfile->fp;
-               fprintf( fp, "<?xml version=\"1.0\"" );
+               if(fprintf( fp, "<?xml version=\"1.0\"" ) < 0)
+                       goto revert;
                if( props->encoding && *props->encoding ) {
-                       fprintf( fp, " encoding=\"%s\"", props->encoding );
+                       if(fprintf( fp, " encoding=\"%s\"", props->encoding ) < 0)
+                               goto revert;
                }
-               fprintf( fp, " ?>\n" );
-               xmlprops_write_elem_s( fp, 0, XMLS_ELTAG_PROP_LIST );
-               fputs( ">\n", fp );
+               if(fprintf( fp, " ?>\n" ) < 0)
+                       goto revert;
+               if(xmlprops_write_elem_s( fp, 0, XMLS_ELTAG_PROP_LIST ) < 0)
+                       goto revert;
+               if(fputs( ">\n", fp ) == EOF)
+                       goto revert;
 
                /* Output all properties */
-               g_hash_table_foreach( props->propertyTable, xmlprops_write_vis, fp );
+               data.fp = fp;
+               data.error = 0;
+               g_hash_table_foreach( props->propertyTable, xmlprops_write_vis, &data );
 
-               xmlprops_write_elem_e( fp, 0, XMLS_ELTAG_PROP_LIST );
+               if (data.error)
+                       goto revert;
+
+               if(xmlprops_write_elem_e( fp, 0, XMLS_ELTAG_PROP_LIST ) < 0)
+                       goto revert;
+               
                props->retVal = MGU_SUCCESS;
                if( prefs_file_close( pfile ) < 0 ) {
+                       goto revert;
+               }
+               goto out;
+revert:
+               props->retVal = MGU_ERROR_WRITE;
+               if( prefs_file_close_revert( pfile ) < 0 ) {
                        props->retVal = MGU_ERROR_WRITE;
                }
+       
        }
-
+out:
        return props->retVal;
 }
 
@@ -190,23 +241,34 @@ gint xmlprops_save_file( XmlProperty *props ) {
        props->retVal = MGU_NO_FILE;
        if( props->path == NULL || *props->path == '\0' ) return props->retVal;
        xmlprops_write_to( props, props->path );
-       /*
-       if( props->retVal == MGU_SUCCESS ) {
-       }
-       */
+
        return props->retVal;
 }
 
-static void xmlprops_print_vis( gpointer key, gpointer value, gpointer data ) {
-       FILE *stream = ( FILE * ) data;
+static void xmlprops_print_vis( gpointer key, gpointer value, gpointer d ) {
+       HashLoopData *data = (HashLoopData *)d;
 
-       fprintf( stream, "-\tname/value:\t%s / %s\n", (char *)key, (char *)value );
+       if (fprintf( data->fp, "-\tname/value:\t%s / %s\n", (char *)key, (char *)value ) < 0)
+               data->error = 1;
 }
 
-void xmlprops_print( XmlProperty *props, FILE *stream ) {
-       fprintf( stream, "Property File: %s\n", props->path );
-       g_hash_table_foreach( props->propertyTable, xmlprops_print_vis, stream );
-       fprintf( stream, "---\n" );
+int xmlprops_print( XmlProperty *props, FILE *stream ) {
+       HashLoopData data;
+       
+       if (fprintf( stream, "Property File: %s\n", props->path ) < 0)
+               return -1;
+               
+       data.fp = stream;
+       data.error = 0;
+       g_hash_table_foreach( props->propertyTable, xmlprops_print_vis, &data );
+
+       if (data.error)
+               return -1;
+
+       if (fprintf( stream, "---\n" ) < 0)
+               return -1;
+       
+       return 0;
 }
 
 static void xmlprops_save_property(
index 8d0526d..4f4abc9 100644 (file)
@@ -44,7 +44,7 @@ void xmlprops_clear           ( XmlProperty *props );
 void xmlprops_free             ( XmlProperty *props );
 void xmlprops_set_path         ( XmlProperty *props, const gchar *value );
 void xmlprops_set_encoding     ( XmlProperty *props, const gchar *value );
-void xmlprops_print            ( XmlProperty *props, FILE *stream );
+int xmlprops_print             ( XmlProperty *props, FILE *stream );
 gint xmlprops_load_file                ( XmlProperty *props );
 gint xmlprops_save_file                ( XmlProperty *props );
 void xmlprops_set_property     ( XmlProperty *props, const gchar *name,
index e940564..ff3fb33 100644 (file)
@@ -4700,6 +4700,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
        const gchar *headerentryname;
        const gchar *cc_hdr;
        const gchar *to_hdr;
+       gboolean err = FALSE;
 
        debug_print("Writing redirect header\n");
 
@@ -4721,17 +4722,17 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
                                        strlen("Resent-To") + 2, TRUE);
 
                                if (first_to_address) {
-                                       fprintf(fp, "Resent-To: ");
+                                       err |= (fprintf(fp, "Resent-To: ") < 0);
                                        first_to_address = FALSE;
                                } else {
-                                       fprintf(fp, ",");
+                                       err |= (fprintf(fp, ",") < 0);
                                 }
-                               fprintf(fp, "%s", buf);
+                               err |= (fprintf(fp, "%s", buf) < 0);
                        }
                }
        }
        if (!first_to_address) {
-               fprintf(fp, "\n");
+               err |= (fprintf(fp, "\n") < 0);
        }
 
        first_cc_address = TRUE;
@@ -4749,20 +4750,20 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
                                        strlen("Resent-Cc") + 2, TRUE);
 
                                 if (first_cc_address) {
-                                        fprintf(fp, "Resent-Cc: ");
+                                        err |= (fprintf(fp, "Resent-Cc: ") < 0);
                                         first_cc_address = FALSE;
                                 } else {
-                                        fprintf(fp, ",");
+                                        err |= (fprintf(fp, ",") < 0);
                                 }
-                               fprintf(fp, "%s", buf);
+                               err |= (fprintf(fp, "%s", buf) < 0);
                        }
                }
        }
        if (!first_cc_address) {
-               fprintf(fp, "\n");
+               err |= (fprintf(fp, "\n") < 0);
         }
        
-       return(0);
+       return (err ? -1:0);
 }
 
 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
@@ -4771,6 +4772,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        gchar *str;
        const gchar *entstr;
        /* struct utsname utsbuf; */
+       gboolean err = FALSE;
 
        g_return_val_if_fail(fp != NULL, -1);
        g_return_val_if_fail(compose->account != NULL, -1);
@@ -4778,17 +4780,17 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
 
        /* Resent-Date */
        get_rfc822_date(buf, sizeof(buf));
-       fprintf(fp, "Resent-Date: %s\n", buf);
+       err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
 
        /* Resent-From */
        if (compose->account->name && *compose->account->name) {
                compose_convert_header
                        (compose, buf, sizeof(buf), compose->account->name,
                         strlen("From: "), TRUE);
-               fprintf(fp, "Resent-From: %s <%s>\n",
-                       buf, compose->account->address);
+               err |= (fprintf(fp, "Resent-From: %s <%s>\n",
+                       buf, compose->account->address) < 0);
        } else
-               fprintf(fp, "Resent-From: %s\n", compose->account->address);
+               err |= (fprintf(fp, "Resent-From: %s\n", compose->account->address) < 0);
 
        /* Subject */
        entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
@@ -4798,7 +4800,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
                if (*str != '\0') {
                        compose_convert_header(compose, buf, sizeof(buf), str,
                                               strlen("Subject: "), FALSE);
-                       fprintf(fp, "Subject: %s\n", buf);
+                       err |= (fprintf(fp, "Subject: %s\n", buf) < 0);
                }
        }
 
@@ -4814,15 +4816,16 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
                g_snprintf(buf, sizeof(buf), "%s", "");
        }
        generate_msgid(buf, sizeof(buf));
-       fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
+       err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
        compose->msgid = g_strdup(buf);
 
-       compose_redirect_write_headers_from_headerlist(compose, fp);
+       if (compose_redirect_write_headers_from_headerlist(compose, fp))
+               return -1;
 
        /* separator between header and body */
-       fputs("\n", fp);
+       err |= (fputs("\n", fp) == EOF);
 
-       return 0;
+       return (err ? -1:0);
 }
 
 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
@@ -4832,6 +4835,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
        gchar buf[BUFFSIZE];
        int i = 0;
        gboolean skip = FALSE;
+       gboolean err = FALSE;
        gchar *not_included[]={
                "Return-Path:",         "Delivered-To:",        "Received:",
                "Subject:",             "X-UIDL:",              "AF:",
@@ -4870,7 +4874,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                if (!prefs_common.redirect_keep_from) {
                        if (g_ascii_strncasecmp(buf, "From:",
                                          strlen("From:")) == 0) {
-                               fputs(" (by way of ", fdest);
+                               err |= (fputs(" (by way of ", fdest) == EOF);
                                if (compose->account->name
                                    && *compose->account->name) {
                                        compose_convert_header
@@ -4878,13 +4882,13 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                                                 compose->account->name,
                                                 strlen("From: "),
                                                 FALSE);
-                                       fprintf(fdest, "%s <%s>",
+                                       err |= (fprintf(fdest, "%s <%s>",
                                                buf,
-                                               compose->account->address);
+                                               compose->account->address) < 0);
                                } else
-                                       fprintf(fdest, "%s",
-                                               compose->account->address);
-                               fputs(")", fdest);
+                                       err |= (fprintf(fdest, "%s",
+                                               compose->account->address) < 0);
+                               err |= (fputs(")", fdest) == EOF);
                        }
                }
 
@@ -4892,7 +4896,11 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                        goto error;
        }
 
-       compose_redirect_write_headers(compose, fdest);
+       if (err)
+               goto error;
+
+       if (compose_redirect_write_headers(compose, fdest))
+               goto error;
 
        while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
                if (fwrite(buf, sizeof(gchar), len, fdest) != len)
@@ -5248,7 +5256,8 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        gint num;
         static gboolean lock = FALSE;
        PrefsAccount *mailac = NULL, *newsac = NULL;
-       
+       gboolean err = FALSE;
+
        debug_print("queueing message...\n");
        g_return_val_if_fail(compose->account != NULL, -1);
 
@@ -5306,55 +5315,55 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
        /* queueing variables */
-       fprintf(fp, "AF:\n");
-       fprintf(fp, "NF:0\n");
-       fprintf(fp, "PS:10\n");
-       fprintf(fp, "SRH:1\n");
-       fprintf(fp, "SFN:\n");
-       fprintf(fp, "DSR:\n");
+       err |= (fprintf(fp, "AF:\n") < 0);
+       err |= (fprintf(fp, "NF:0\n") < 0);
+       err |= (fprintf(fp, "PS:10\n") < 0);
+       err |= (fprintf(fp, "SRH:1\n") < 0);
+       err |= (fprintf(fp, "SFN:\n") < 0);
+       err |= (fprintf(fp, "DSR:\n") < 0);
        if (compose->msgid)
-               fprintf(fp, "MID:<%s>\n", compose->msgid);
+               err |= (fprintf(fp, "MID:<%s>\n", compose->msgid) < 0);
        else
-               fprintf(fp, "MID:\n");
-       fprintf(fp, "CFG:\n");
-       fprintf(fp, "PT:0\n");
-       fprintf(fp, "S:%s\n", compose->account->address);
-       fprintf(fp, "RQ:\n");
+               err |= (fprintf(fp, "MID:\n") < 0);
+       err |= (fprintf(fp, "CFG:\n") < 0);
+       err |= (fprintf(fp, "PT:0\n") < 0);
+       err |= (fprintf(fp, "S:%s\n", compose->account->address) < 0);
+       err |= (fprintf(fp, "RQ:\n") < 0);
        if (mailac)
-               fprintf(fp, "SSV:%s\n", mailac->smtp_server);
+               err |= (fprintf(fp, "SSV:%s\n", mailac->smtp_server) < 0);
        else
-               fprintf(fp, "SSV:\n");
+               err |= (fprintf(fp, "SSV:\n") < 0);
        if (newsac)
-               fprintf(fp, "NSV:%s\n", newsac->nntp_server);
+               err |= (fprintf(fp, "NSV:%s\n", newsac->nntp_server) < 0);
        else
-               fprintf(fp, "NSV:\n");
-       fprintf(fp, "SSH:\n");
+               err |= (fprintf(fp, "NSV:\n") < 0);
+       err |= (fprintf(fp, "SSH:\n") < 0);
        /* write recepient list */
        if (compose->to_list) {
-               fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
+               err |= (fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data) < 0);
                for (cur = compose->to_list->next; cur != NULL;
                     cur = cur->next)
-                       fprintf(fp, ",<%s>", (gchar *)cur->data);
-               fprintf(fp, "\n");
+                       err |= (fprintf(fp, ",<%s>", (gchar *)cur->data) < 0);
+               err |= (fprintf(fp, "\n") < 0);
        }
        /* write newsgroup list */
        if (compose->newsgroup_list) {
-               fprintf(fp, "NG:");
-               fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
+               err |= (fprintf(fp, "NG:") < 0);
+               err |= (fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data) < 0);
                for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
-                       fprintf(fp, ",%s", (gchar *)cur->data);
-               fprintf(fp, "\n");
+                       err |= (fprintf(fp, ",%s", (gchar *)cur->data) < 0);
+               err |= (fprintf(fp, "\n") < 0);
        }
        /* Sylpheed account IDs */
        if (mailac)
-               fprintf(fp, "MAID:%d\n", mailac->account_id);
+               err |= (fprintf(fp, "MAID:%d\n", mailac->account_id) < 0);
        if (newsac)
-               fprintf(fp, "NAID:%d\n", newsac->account_id);
+               err |= (fprintf(fp, "NAID:%d\n", newsac->account_id) < 0);
 
        
        if (compose->privacy_system != NULL) {
-               fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system);
-               fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
+               err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
+               err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
                if (compose->use_encryption) {
                        gchar *encdata;
                        if (!compose_warn_encryption(compose)) {
@@ -5374,12 +5383,12 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                        }
                        if (encdata != NULL) {
                                if (strcmp(encdata, "_DONT_ENCRYPT_")) {
-                                       fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
-                                       fprintf(fp, "X-Claws-Encrypt-Data:%s\n", 
-                                               encdata);
+                                       err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
+                                       err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n", 
+                                               encdata) < 0);
                                } /* else we finally dont want to encrypt */
                        } else {
-                               fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
+                               err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
                                /* and if encdata was null, it means there's been a problem in 
                                 * key selection */
                                lock = FALSE;
@@ -5397,19 +5406,19 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                gchar *savefolderid;
                
                savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-               fprintf(fp, "SCF:%s\n", savefolderid);
+               err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
                g_free(savefolderid);
        }
        /* Save copy folder */
        if (compose->return_receipt) {
-               fprintf(fp, "RRCPT:1\n");
+               err |= (fprintf(fp, "RRCPT:1\n") < 0);
        }
        /* Message-ID of message replying to */
        if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->replyinfo->folder);
-               fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
+               err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
                g_free(folderid);
        }
        /* Message-ID of message forwarding to */
@@ -5417,12 +5426,12 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->fwdinfo->folder);
-               fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
+               err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
                g_free(folderid);
        }
 
        /* end of headers */
-       fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
+       err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
 
        if (compose->redirect_filename != NULL) {
                if (compose_redirect_write_to_file(compose, fp) < 0) {
@@ -5442,7 +5451,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                        return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
                }
        }
-
+       if (err == TRUE) {
+               g_warning("failed to write queue message\n");
+               fclose(fp);
+               g_unlink(tmp);
+               g_free(tmp);
+               lock = FALSE;
+               return -2;
+       }
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
                g_unlink(tmp);
@@ -8432,7 +8448,8 @@ gboolean compose_draft (gpointer data, guint action)
        MsgInfo *newmsginfo;
        FILE *fp;
        gboolean target_locked = FALSE;
-       
+       gboolean err = FALSE;
+
        if (lock) return FALSE;
 
        if (compose->sending)
@@ -8456,7 +8473,7 @@ gboolean compose_draft (gpointer data, guint action)
                              G_DIR_SEPARATOR, compose);
        if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
-               goto unlock;
+               goto warn_err;
        }
 
        /* chmod for security */
@@ -8466,23 +8483,23 @@ gboolean compose_draft (gpointer data, guint action)
        }
 
        /* Save draft infos */
-       fprintf(fp, "X-Claws-Account-Id:%d\n", compose->account->account_id);
-       fprintf(fp, "S:%s\n", compose->account->address);
+       err |= (fprintf(fp, "X-Claws-Account-Id:%d\n", compose->account->account_id) < 0);
+       err |= (fprintf(fp, "S:%s\n", compose->account->address) < 0);
 
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
                gchar *savefolderid;
 
                savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-               fprintf(fp, "SCF:%s\n", savefolderid);
+               err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
                g_free(savefolderid);
        }
        if (compose->return_receipt) {
-               fprintf(fp, "RRCPT:1\n");
+               err |= (fprintf(fp, "RRCPT:1\n") < 0);
        }
        if (compose->privacy_system) {
-               fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
-               fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
-               fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system);
+               err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
+               err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
+               err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
        }
 
        /* Message-ID of message replying to */
@@ -8490,7 +8507,7 @@ gboolean compose_draft (gpointer data, guint action)
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->replyinfo->folder);
-               fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
+               err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
                g_free(folderid);
        }
        /* Message-ID of message forwarding to */
@@ -8498,20 +8515,25 @@ gboolean compose_draft (gpointer data, guint action)
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->fwdinfo->folder);
-               fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
+               err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
                g_free(folderid);
        }
 
        /* end of headers */
-       fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
+       err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
+
+       if (err) {
+               fclose(fp);
+               goto warn_err;
+       }
 
        if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
                fclose(fp);
-               g_unlink(tmp);
-               g_free(tmp);
-               goto unlock;
+               goto warn_err;
+       }
+       if (fclose(fp) == EOF) {
+               goto warn_err;
        }
-       fclose(fp);
        
        if (compose->targetinfo) {
                target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
@@ -8537,6 +8559,7 @@ gboolean compose_draft (gpointer data, guint action)
                debug_print("got draft msgnum %d from adding\n", msgnum);
        }
        if (msgnum < 0) {
+warn_err:
                g_unlink(tmp);
                g_free(tmp);
                if (action != COMPOSE_AUTO_SAVE) {
index 8dca09f..4e2bf74 100644 (file)
@@ -1181,7 +1181,8 @@ void exporthtml_save_settings( ExportHtmlCtl *ctl ) {
        xmlprops_set_property_b( props, EXMLPROP_BANDING, ctl->banding );
        xmlprops_set_property_b( props, EXMLPROP_FMT_EMAIL, ctl->linkEMail );
        xmlprops_set_property_b( props, EXMLPROP_FMT_ATTRIB, ctl->showAttribs );
-       xmlprops_save_file( props );
+       if (xmlprops_save_file( props ) != MGU_SUCCESS)
+               g_warning("can't save settings");
        xmlprops_free( props );
 }
 
index 3ce4615..9129267 100644 (file)
@@ -644,7 +644,8 @@ void exportldif_save_settings( ExportLdifCtl *ctl ) {
        xmlprops_set_property_i( props, EXMLPROP_RDN_INDEX, ctl->rdnIndex );
        xmlprops_set_property_b( props, EXMLPROP_USE_DN, ctl->useDN );
        xmlprops_set_property_b( props, EXMLPROP_EXCL_EMAIL, ctl->excludeEMail );
-       xmlprops_save_file( props );
+       if (xmlprops_save_file( props ) != MGU_SUCCESS)
+               g_warning("can't save settings");
        xmlprops_free( props );
 }
 
index 38ed4ed..a7d5cce 100644 (file)
@@ -3810,13 +3810,6 @@ static gchar *folder_get_list_path(void)
        return filename;
 }
 
-#define PUT_ESCAPE_STR(fp, attr, str)                  \
-{                                                      \
-       fputs(" " attr "=\"", fp);                      \
-       xml_file_put_escape_str(fp, str);               \
-       fputs("\"", fp);                                \
-}
-
 static gpointer folder_item_to_xml(gpointer nodedata, gpointer data)
 {
        FolderItem *item = (FolderItem *) nodedata;
@@ -4384,5 +4377,3 @@ gboolean folder_get_sort_type             (Folder         *folder,
        folder->klass->get_sort_type(folder, sort_key, sort_type); 
        return TRUE;
 }
-
-#undef PUT_ESCAPE_STR
index 76ec273..d3a17af 100644 (file)
@@ -424,18 +424,20 @@ backup_mode:
        return (r == 0);
 }
 
-static void migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
+static int migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
 {
        FILE *oldfp, *newfp;
        gchar *plugin_path, *old_plugin_path, *new_plugin_path;
        gchar buf[BUFFSIZE];
+       gboolean err = FALSE;
+
        oldfp = g_fopen(old_rc, "r");
        if (!oldfp)
-               return;
+               return -1;
        newfp = g_fopen(new_rc, "w");
        if (!newfp) {
                fclose(oldfp);
-               return;
+               return -1;
        }
        
        plugin_path = g_strdup(get_plugin_dir());
@@ -452,19 +454,22 @@ static void migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
        debug_print("replacing %s with %s\n", old_plugin_path, new_plugin_path);
        while (fgets(buf, sizeof(buf), oldfp)) {
                if (strncmp(buf, old_plugin_path, strlen(old_plugin_path))) {
-                       fputs(buf, newfp);
+                       err |= (fputs(buf, newfp) == EOF);
                } else {
                        debug_print("->replacing %s", buf);
                        debug_print("  with %s%s", new_plugin_path, buf+strlen(old_plugin_path));
-                       fputs(new_plugin_path, newfp);
-                       fputs(buf+strlen(old_plugin_path), newfp);
+                       err |= (fputs(new_plugin_path, newfp) == EOF);
+                       err |= (fputs(buf+strlen(old_plugin_path), newfp) == EOF);
                }
        }
        g_free(plugin_path);
        g_free(new_plugin_path);
        g_free(old_plugin_path);
        fclose(oldfp);
-       fclose(newfp);
+       if (fclose(newfp) == EOF)
+               err = TRUE;
+       
+       return (err ? -1:0);
 }
 
 #ifdef HAVE_LIBSM
index 102d3ef..8198b63 100644 (file)
@@ -2118,7 +2118,7 @@ gchar *matching_build_command(const gchar *cmd, MsgInfo *info)
  *\param       fp File
  *\param       prefs_filtering List of filtering conditions
  */
-static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
+static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
 {
        GSList *cur = NULL;
 
@@ -2136,19 +2136,19 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                if (prop->enabled) {
                        if (fputs("enabled ", fp) == EOF) {
                                FILE_OP_ERROR("filtering config", "fputs");
-                               return;
+                               return -1;
                        }
                } else {
                        if (fputs("disabled ", fp) == EOF) {
                                FILE_OP_ERROR("filtering config", "fputs");
-                               return;
+                               return -1;
                        }
                }
 
                if (fputs("rulename \"", fp) == EOF) {
                        FILE_OP_ERROR("filtering config", "fputs");
                        g_free(filtering_str);
-                       return;
+                       return -1;
                }
                tmp_name = prop->name;
                while (tmp_name && *tmp_name != '\0') {
@@ -2156,14 +2156,14 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                                if (fputc(*tmp_name, fp) == EOF) {
                                        FILE_OP_ERROR("filtering config", "fputs || fputc");
                                        g_free(filtering_str);
-                                       return;
+                                       return -1;
                                }
                        } else if (*tmp_name == '"') {
                                if (fputc('\\', fp) == EOF ||
                                    fputc('"', fp) == EOF) {
                                        FILE_OP_ERROR("filtering config", "fputs || fputc");
                                        g_free(filtering_str);
-                                       return;
+                                       return -1;
                                }
                        }
                        tmp_name ++;
@@ -2171,7 +2171,7 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                if (fputs("\" ", fp) == EOF) {
                        FILE_OP_ERROR("filtering config", "fputs");
                        g_free(filtering_str);
-                       return;
+                       return -1;
                }
 
                if (prop->account_id != 0) {
@@ -2181,7 +2181,7 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                        if (fputs(tmp, fp) == EOF) {
                                FILE_OP_ERROR("filtering config", "fputs");
                                g_free(tmp);
-                               return;
+                               return -1;
                        }
                        g_free(tmp);
                }
@@ -2190,12 +2190,19 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                    fputc('\n', fp) == EOF) {
                        FILE_OP_ERROR("filtering config", "fputs || fputc");
                        g_free(filtering_str);
-                       return;
+                       return -1;
                }
                g_free(filtering_str);
        }
+       
+       return 0;
 }
 
+typedef struct _NodeLoopData {
+       FILE *fp;
+       gboolean error;
+} NodeLoopData;
+
 /*!
  *\brief       Write matchers from a folder item
  *
@@ -2204,10 +2211,10 @@ static void prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
  *
  *\return      gboolean FALSE
  */
-static gboolean prefs_matcher_write_func(GNode *node, gpointer data)
+static gboolean prefs_matcher_write_func(GNode *node, gpointer d)
 {
        FolderItem *item;
-       FILE *fp = data;
+       NodeLoopData *data = (NodeLoopData *)d;
        gchar *id;
        GSList *prefs_filtering;
 
@@ -2221,11 +2228,20 @@ static gboolean prefs_matcher_write_func(GNode *node, gpointer data)
         prefs_filtering = item->prefs->processing;
 
        if (prefs_filtering != NULL) {
-               fprintf(fp, "[%s]\n", id);
-               prefs_filtering_write(fp, prefs_filtering);
-               fputc('\n', fp);
+               if (fprintf(data->fp, "[%s]\n", id) < 0) {
+                       data->error = TRUE;
+                       goto fail;
+               }
+               if (prefs_filtering_write(data->fp, prefs_filtering) < 0) {
+                       data->error = TRUE;
+                       goto fail;
+               }
+               if (fputc('\n', data->fp) == EOF) {
+                       data->error = TRUE;
+                       goto fail;
+               }
        }
-
+fail:
        g_free(id);
 
        return FALSE;
@@ -2236,32 +2252,44 @@ static gboolean prefs_matcher_write_func(GNode *node, gpointer data)
  *
  *\param       fp File
  */
-static void prefs_matcher_save(FILE *fp)
+static int prefs_matcher_save(FILE *fp)
 {
        GList *cur;
+       NodeLoopData data;
+       
+       data.fp = fp;
+       data.error = FALSE;
 
        for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
                Folder *folder;
 
                folder = (Folder *) cur->data;
                g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
-                               prefs_matcher_write_func, fp);
+                               prefs_matcher_write_func, &data);
        }
         
+       if (data.error == TRUE)
+               return -1;
+
         /* pre global rules */
-        fprintf(fp, "[preglobal]\n");
-        prefs_filtering_write(fp, pre_global_processing);
-        fputc('\n', fp);
+        if (fprintf(fp, "[preglobal]\n") < 0 ||
+            prefs_filtering_write(fp, pre_global_processing) < 0 ||
+            fputc('\n', fp) == EOF)
+               return -1;
 
         /* post global rules */
-        fprintf(fp, "[postglobal]\n");
-        prefs_filtering_write(fp, post_global_processing);
-        fputc('\n', fp);
+        if (fprintf(fp, "[postglobal]\n") < 0 ||
+            prefs_filtering_write(fp, post_global_processing) < 0 ||
+            fputc('\n', fp) == EOF)
+               return -1;
         
         /* filtering rules */
-        fprintf(fp, "[filtering]\n");
-        prefs_filtering_write(fp, filtering_rules);
-        fputc('\n', fp);
+       if (fprintf(fp, "[filtering]\n") < 0 ||
+            prefs_filtering_write(fp, filtering_rules) < 0 ||
+            fputc('\n', fp) == EOF)
+               return -1;
+
+       return 0;
 }
 
 /*!
@@ -2283,14 +2311,13 @@ void prefs_matcher_write_config(void)
                return;
        }
 
-
-       prefs_matcher_save(pfile->fp);
-
        g_free(rcpath);
 
-       if (prefs_file_close(pfile) < 0) {
+       if (prefs_matcher_save(pfile->fp) < 0) {
                g_warning("failed to write configuration to file\n");
-               return;
+               prefs_file_close_revert(pfile);
+       } else if (prefs_file_close(pfile) < 0) {
+               g_warning("failed to save configuration to file\n");
        }
 }
 
@@ -2302,7 +2329,7 @@ static void matcher_add_rulenames(const gchar *rcpath)
        FILE *src = g_fopen(rcpath, "rb");
        FILE *dst = g_fopen(newpath, "wb");
        gchar buf[BUFFSIZE];
-
+       int r;
        if (dst == NULL) {
                perror("fopen");
                g_free(newpath);
@@ -2314,10 +2341,10 @@ static void matcher_add_rulenames(const gchar *rcpath)
                && strncmp(buf, "rulename \"", 10)
                && strncmp(buf, "enabled rulename \"", 18)
                && strncmp(buf, "disabled rulename \"", 18)) {
-                       fwrite("enabled rulename \"\" ",
+                       r = fwrite("enabled rulename \"\" ",
                                strlen("enabled rulename \"\" "), 1, dst);
                }
-               fwrite(buf, strlen(buf), 1, dst);
+               r = fwrite(buf, strlen(buf), 1, dst);
        }
        fclose(dst);
        fclose(src);
index b2e9d1d..0e695a6 100644 (file)
@@ -319,8 +319,12 @@ gint lock_mbox(const gchar *base, LockType type)
                        return -1;
                }
 
-               fprintf(lockfp, "%d\n", getpid());
-               fclose(lockfp);
+               if (fprintf(lockfp, "%d\n", getpid()) < 0 ||
+                   fclose(lockfp) == EOF) {
+                       FILE_OP_ERROR(lockfile, "fopen||fclose");
+                       g_free(lockfile);
+                       return -1;
+               }
 
                locklink = g_strconcat(base, ".lock", NULL);
                while (link(lockfile, locklink) < 0) {
@@ -528,6 +532,8 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
        FILE *msg_fp;
        FILE *mbox_fp;
        gchar buf[BUFFSIZE];
+       int err = 0;
+
        gint msgs = 1, total = g_slist_length(mlist);
        if (g_file_test(mbox, G_FILE_TEST_EXISTS) == TRUE) {
                if (alertpanel_full(_("Overwrite mbox file"),
@@ -570,8 +576,15 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                         sizeof(buf));
                extract_address(buf);
 
-               fprintf(mbox_fp, "From %s %s",
-                       buf, ctime_r(&msginfo->date_t, buft));
+               if (fprintf(mbox_fp, "From %s %s",
+                       buf, ctime_r(&msginfo->date_t, buft)) < 0) {
+                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                       funlockfile(msg_fp);
+#endif
+                       fclose(msg_fp);
+                       goto out;
+               }
 
                buf[0] = '\0';
                
@@ -585,21 +598,51 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                        while ((buf[offset] == '>')) {
                                offset++;
                        }
-                       if (!strncmp(buf+offset, "From ", 5))
-                               SC_FPUTC('>', mbox_fp);
-                       SC_FPUTS(buf, mbox_fp);
+                       if (!strncmp(buf+offset, "From ", 5)) {
+                               if (SC_FPUTC('>', mbox_fp) == EOF) {
+                                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                                       funlockfile(msg_fp);
+#endif
+                                       fclose(msg_fp);
+                                       goto out;
+                               }
+                       }
+                       if (SC_FPUTS(buf, mbox_fp) == EOF) {
+                               err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                               funlockfile(msg_fp);
+#endif
+                               fclose(msg_fp);
+                               goto out;
+                       }
                }
 
                /* force last line to end w/ a newline */
                len = strlen(buf);
                if (len > 0) {
                        len--;
-                       if ((buf[len] != '\n') && (buf[len] != '\r'))
-                               SC_FPUTC('\n', mbox_fp);
+                       if ((buf[len] != '\n') && (buf[len] != '\r')) {
+                               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+                                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                                       funlockfile(msg_fp);
+#endif
+                                       fclose(msg_fp);
+                                       goto out;
+                               }
+                       }
                }
 
                /* add a trailing empty line */
-               SC_FPUTC('\n', mbox_fp);
+               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+                       err = -1;
+#ifdef HAVE_FGETS_UNLOCKED
+                       funlockfile(msg_fp);
+#endif
+                       fclose(msg_fp);
+                       goto out;
+               }
 
 #ifdef HAVE_FGETS_UNLOCKED
                funlockfile(msg_fp);
@@ -609,6 +652,8 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                if (msgs%500 == 0)
                        GTK_EVENTS_FLUSH();
        }
+
+out:
        statusbar_progress_all(0,0,0);
        statuswindow_pop_all();
 
@@ -617,7 +662,7 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
 #endif
        fclose(mbox_fp);
 
-       return 0;
+       return err;
 }
 
 /* read all messages in SRC, and store them into one MBOX file. */
index e753ff6..17fdb81 100644 (file)
@@ -665,24 +665,29 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        addrp = addr;
        
        /* write queue headers */
-       fprintf(fp, "AF:\n");
-       fprintf(fp, "NF:0\n");
-       fprintf(fp, "PS:10\n");
-       fprintf(fp, "SRH:1\n");
-       fprintf(fp, "SFN:\n");
-       fprintf(fp, "DSR:\n");
-       fprintf(fp, "MID:\n");
-       fprintf(fp, "CFG:\n");
-       fprintf(fp, "PT:0\n");
-       fprintf(fp, "S:%s\n", account->address);
-       fprintf(fp, "RQ:\n");
-       if (account->smtp_server)
-               fprintf(fp, "SSV:%s\n", account->smtp_server);
-       else
-               fprintf(fp, "SSV:\n");
-       fprintf(fp, "SSH:\n");
-       fprintf(fp, "R:<%s>\n", addrp);
-       
+       if (fprintf(fp, "AF:\n"
+                   "NF:0\n"
+                   "PS:10\n"
+                   "SRH:1\n"
+                   "SFN:\n"
+                   "DSR:\n"
+                   "MID:\n"
+                   "CFG:\n"
+                   "PT:0\n"
+                   "S:%s\n"
+                   "RQ:\n"
+                   "SSV:%s\n"
+                   "SSH:\n"
+                   "R:<%s>\n", 
+                   account->address,
+                   account->smtp_server?account->smtp_server:"",
+                   addrp) < 0) {
+               g_free(addrp);
+               fclose(fp);
+               g_unlink(tmp);
+               return -1;
+       }
+
        g_free(addrp);
        
        /* check whether we need to save the message */
@@ -691,31 +696,61 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                outbox = NULL;
        if (outbox) {
                path = folder_item_get_identifier(outbox);
-               fprintf(fp, "SCF:%s\n", path);
+               if (fprintf(fp, "SCF:%s\n", path) < 0) {
+                       g_free(path);
+                       fclose(fp);
+                       g_unlink(tmp);
+                       return -1;
+               }
                g_free(path);
        }               
 
-       fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
-       
+       if (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0) {
+               fclose(fp);
+               g_unlink(tmp);
+               return -1;
+       }
+
        /* Date */
        get_rfc822_date(buf, sizeof(buf));
-       fprintf(fp, "Date: %s\n", buf);
+       if (fprintf(fp, "Date: %s\n", buf) < 0) {
+               fclose(fp);
+               g_unlink(tmp);
+               return -1;
+       }
 
        /* From */
        if (account->name && *account->name) {
                notification_convert_header
                        (buf, sizeof(buf), account->name,
                         strlen("From: "));
-               fprintf(fp, "From: %s <%s>\n", buf, account->address);
+               if (fprintf(fp, "From: %s <%s>\n", buf, account->address) < 0) {
+                       fclose(fp);
+                       g_unlink(tmp);
+                       return -1;
+               }
        } else
-               fprintf(fp, "From: %s\n", account->address);
+               if (fprintf(fp, "From: %s\n", account->address) < 0) {
+                       fclose(fp);
+                       g_unlink(tmp);
+                       return -1;
+               }
 
-       fprintf(fp, "To: %s\n", to);
+
+       if (fprintf(fp, "To: %s\n", to) < 0) {
+               fclose(fp);
+               g_unlink(tmp);
+               return -1;
+       }
 
        /* Subject */
        notification_convert_header(buf, sizeof(buf), msginfo->subject,
                                    strlen("Subject: "));
-       fprintf(fp, "Subject: Disposition notification: %s\n", buf);
+       if (fprintf(fp, "Subject: Disposition notification: %s\n", buf) < 0) {
+               fclose(fp);
+               g_unlink(tmp);
+               return -1;
+       }
 
        /* Message ID */
        if (account->set_domain && account->domain) {
@@ -729,7 +764,12 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                g_snprintf(buf, sizeof(buf), "%s", "");
        }
        generate_msgid(buf, sizeof(buf));
-       fprintf(fp, "Message-ID: <%s>\n", buf);
+       if (fprintf(fp, "Message-ID: <%s>\n", buf) < 0) {
+               fclose(fp);
+               g_unlink(tmp);
+               return -1;
+       }
+
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
index f1142d3..c663b49 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -1343,6 +1343,7 @@ static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
        FILE *mh_sequences_old_fp, *mh_sequences_new_fp;
        gchar buf[BUFFSIZE];
        gchar *path = NULL;
+       gboolean err = FALSE;
        START_TIMING("");
 
        if (!item)
@@ -1392,16 +1393,21 @@ static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
                        cur = cur ? cur->next:NULL;
                } while (cur || (start > 0 && end > 0));
                if (sequence && *sequence) {
-                       fprintf(mh_sequences_new_fp, "%s%s\n", 
-                                       get_unseen_seq_name(), sequence);
-                       debug_print("wrote unseen sequence: '%s%s'\n", 
+                       if (fprintf(mh_sequences_new_fp, "%s%s\n", 
+                                       get_unseen_seq_name(), sequence) < 0)
+                               err = TRUE;
+                       else
+                               debug_print("wrote unseen sequence: '%s%s'\n", 
                                        get_unseen_seq_name(), sequence);
                }
                /* rewrite the rest of the file */
                if ((mh_sequences_old_fp = g_fopen(mh_sequences_old, "r+b")) != NULL) {
                        while (fgets(buf, sizeof(buf), mh_sequences_old_fp) != NULL) {
                                if (strncmp(buf, get_unseen_seq_name(), strlen(get_unseen_seq_name())))
-                                       fprintf(mh_sequences_new_fp, "%s", buf);
+                                       if (fprintf(mh_sequences_new_fp, "%s", buf) < 0) {
+                                               err = TRUE;
+                                               break;
+                                       }
                        }
                        fclose(mh_sequences_old_fp);
                }
@@ -1410,9 +1416,11 @@ static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
 #if 0
                fsync(fileno(mh_sequences_new_fp));
 #endif
-               fclose(mh_sequences_new_fp);
+               if (fclose(mh_sequences_new_fp) == EOF)
+                       err = TRUE;
 
-               g_rename(mh_sequences_new, mh_sequences_old);
+               if (!err)
+                       g_rename(mh_sequences_new, mh_sequences_old);
                g_free(sequence);
                procmsg_msg_list_free(msglist);
        }
index dd81ba8..df66d4c 100644 (file)
@@ -825,18 +825,36 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
                g_warning("can't change file mode\n");
        }
        
-       fprintf(tmpfp, "From: %s\r\n", msginfo->from);
-       fprintf(tmpfp, "Newsgroups: %s\r\n", msginfo->newsgroups);
-       fprintf(tmpfp, "Subject: cmsg cancel <%s>\r\n", msginfo->msgid);
-       fprintf(tmpfp, "Control: cancel <%s>\r\n", msginfo->msgid);
-       fprintf(tmpfp, "Approved: %s\r\n", msginfo->from);
-       fprintf(tmpfp, "X-Cancelled-by: %s\r\n", msginfo->from);
        get_rfc822_date(buf, sizeof(buf));
-       fprintf(tmpfp, "Date: %s\r\n", buf);
-       fprintf(tmpfp, "\r\n");
-       fprintf(tmpfp, "removed with Claws Mail\r\n");
+       if (fprintf(tmpfp, "From: %s\r\n"
+                      "Newsgroups: %s\r\n"
+                      "Subject: cmsg cancel <%s>\r\n"
+                      "Control: cancel <%s>\r\n"
+                      "Approved: %s\r\n"
+                      "X-Cancelled-by: %s\r\n"
+                      "Date: %s\r\n"
+                      "\r\n"
+                      "removed with Claws Mail\r\n",
+                      msginfo->from,
+                      msginfo->newsgroups,
+                      msginfo->msgid,
+                      msginfo->msgid,
+                      msginfo->from,
+                      msginfo->from,
+                      buf) < 0) {
+               FILE_OP_ERROR(tmp, "fprintf");
+               fclose(tmpfp);
+               g_unlink(tmp);
+               g_free(tmp);
+               return -1;
+       }
 
-       fclose(tmpfp);
+       if (fclose(tmpfp) == EOF) {
+               FILE_OP_ERROR(tmp, "fclose");
+               g_unlink(tmp);
+               g_free(tmp);
+               return -1;
+       }
 
        news_post(folder, tmp);
        remove(tmp);
index fac09d1..dab970d 100644 (file)
@@ -214,8 +214,15 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                        }
                }
                if (strcmp(tinfo->extradata->partial_recv, uidl)) {
-                       fprintf(fpnew, "%s\t%ld\t%s\n", 
-                               uidl, (long int) recv_time, partial_recv);
+                       if (fprintf(fpnew, "%s\t%ld\t%s\n", 
+                               uidl, (long int) recv_time, partial_recv) < 0) {
+                               FILE_OP_ERROR(pathnew, "fprintf");
+                               fclose(fpnew);
+                               fclose(fp);
+                               g_free(path);
+                               g_free(pathnew);
+                               goto bail;
+                       }
                } else {
                        gchar *stat = NULL;
                        if (download == POP3_PARTIAL_DLOAD_DLOAD) {
@@ -230,12 +237,25 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                        else if (download == POP3_PARTIAL_DLOAD_DELE)
                                stat = g_strdup("0");
                        
-                       fprintf(fpnew, "%s\t%ld\t%s\n", 
-                               uidl, (long int) recv_time, stat);
+                       if (fprintf(fpnew, "%s\t%ld\t%s\n", 
+                               uidl, (long int) recv_time, stat) < 0) {
+                               FILE_OP_ERROR(pathnew, "fprintf");
+                               fclose(fpnew);
+                               fclose(fp);
+                               g_free(path);
+                               g_free(pathnew);
+                               goto bail;
+                       }
                        g_free(stat);
                }
        }
-       fclose(fpnew);
+       if (fclose(fpnew) == EOF) {
+               FILE_OP_ERROR(pathnew, "fclose");
+               fclose(fp);
+               g_free(path);
+               g_free(pathnew);
+               goto bail;
+       }
        fclose(fp);
 
        move_file(pathnew, path, TRUE);
@@ -255,23 +275,47 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                goto bail;
        }
        
-       fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
-                       download);
+       if (fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
+                       download) < 0) {
+               FILE_OP_ERROR(pathnew, "fprintf");
+               fclose(fpnew);
+               fclose(fp);
+               g_free(pathnew);
+               goto bail;
+       }
        while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
                if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
                && !strncmp(buf, "SC-Marked-For-Download:", 
                            strlen("SC-Marked-For-Download:"))) {
-                       fprintf(fpnew, "%s", 
-                        buf+strlen("SC-Marked-For-Download: x\n"));
+                       if (fprintf(fpnew, "%s", 
+                        buf+strlen("SC-Marked-For-Download: x\n")) < 0) {
+                               FILE_OP_ERROR(pathnew, "fprintf");
+                               fclose(fpnew);
+                               fclose(fp);
+                               g_free(pathnew);
+                               goto bail;
+                       }
                        continue;
                } else if (strlen(buf) == strlen("SC-Marked-For-Download: x\n")
                && !strncmp(buf, "SC-Marked-For-Download:", 
                            strlen("SC-Marked-For-Download:"))) {
                        continue;
                }
-               fprintf(fpnew, "%s", buf);
+               if (fprintf(fpnew, "%s", buf) < 0) {
+                       FILE_OP_ERROR(pathnew, "fprintf");
+                       fclose(fpnew);
+                       fclose(fp);
+                       g_free(pathnew);
+                       goto bail;
+               }
        }
-       fclose(fpnew);
+       if (fclose(fpnew) == EOF) {
+               FILE_OP_ERROR(pathnew, "fclose");
+               fclose(fp);
+               g_free(pathnew);
+               goto bail;
+       }
+
        fclose(fp);
        g_unlink(filename);
        rename(pathnew, filename);
index e9af909..3d04b7f 100644 (file)
@@ -280,18 +280,28 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                                        fclose (output);
                                                else {
                                                        gchar tmpbuf[BUFFSIZE];
+                                                       gboolean err = FALSE;
                                                        const gchar *bogosity = *parts[1] == 'S' ? "Spam":
                                                                                 (*parts[1] == 'H' ? "Ham":"Unsure");
                                                        gchar *tmpstr = g_strdup_printf(
                                                                        "X-Claws-Bogosity: %s, spamicity=%s%s\n",
                                                                        bogosity, parts[2],
                                                                        whitelisted?" [whitelisted]":"");
-                                                       fwrite(tmpstr, 1, strlen(tmpstr), output);
-                                                       while (fgets(tmpbuf, sizeof(buf), input))
-                                                               fputs(tmpbuf, output);
+                                                       if (fwrite(tmpstr, 1, strlen(tmpstr), output) < strlen(tmpstr)) {
+                                                               err = TRUE;
+                                                       } else {
+                                                               while (fgets(tmpbuf, sizeof(buf), input)) {
+                                                                       if (fputs(tmpbuf, output) == EOF) {
+                                                                               err = TRUE;
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       }
                                                        fclose(input);
-                                                       fclose(output);
-                                                       move_file(tmpfile, file, TRUE);
+                                                       if (fclose(output) == EOF)
+                                                               err = TRUE;
+                                                       if (!err)
+                                                               move_file(tmpfile, file, TRUE);
                                                        g_free(tmpstr);
                                                }
                                                g_free(tmpfile);
@@ -865,9 +875,11 @@ void bogofilter_save_config(void)
                prefs_file_close_revert(pfile);
                return;
        }
-       fprintf(pfile->fp, "\n");
-
-       prefs_file_close(pfile);
+        if (fprintf(pfile->fp, "\n") < 0) {
+               FILE_OP_ERROR(rcpath, "fprintf");
+               prefs_file_close_revert(pfile);
+       } else
+               prefs_file_close(pfile);
 }
 
 void bogofilter_set_message_callback(MessageCallback callback)
index 9e92804..b10cea7 100644 (file)
@@ -201,9 +201,11 @@ void clamav_save_config(void)
                prefs_file_close_revert(pfile);
                return;
        }
-       fprintf(pfile->fp, "\n");
-
-       prefs_file_close(pfile);
+        if (fprintf(pfile->fp, "\n") < 0) {
+               FILE_OP_ERROR(rcpath, "fprintf");
+               prefs_file_close_revert(pfile);
+       } else
+               prefs_file_close(pfile);
 }
 
 void clamav_set_message_callback(MessageCallback callback)
index 0a2de22..2f0f23f 100644 (file)
@@ -173,6 +173,10 @@ static void save_dillo_prefs(PrefsPage *page)
           prefs_file_close_revert(pref_file);
           return;
         }
-        fprintf(pref_file->fp, "\n");
-        prefs_file_close(pref_file);
+
+        if (fprintf(pref_file->fp, "\n") < 0) {
+               FILE_OP_ERROR(rc_file_path, "fprintf");
+               prefs_file_close_revert(pref_file);
+       } else
+               prefs_file_close(pref_file);
 }
index d4d907d..2e8c3e4 100644 (file)
@@ -447,9 +447,11 @@ void prefs_gpg_save_config(void)
                prefs_file_close_revert(pfile);
                return;
        }
-       fprintf(pfile->fp, "\n");
-
-       prefs_file_close(pfile);
+        if (fprintf(pfile->fp, "\n") < 0) {
+               FILE_OP_ERROR(rcpath, "fprintf");
+               prefs_file_close_revert(pfile);
+       } else
+               prefs_file_close(pfile);
 }
 
 struct GPGAccountConfig *prefs_gpg_account_get_config(PrefsAccount *account)
@@ -594,7 +596,7 @@ gboolean prefs_gpg_should_skip_encryption_warning(const gchar *systemid)
        systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
                                ",", -1);
        while (systems && systems[i]) {
-               g_print(" cmp %s %s\n", systems[i], systemid);
+               debug_print(" cmp %s %s\n", systems[i], systemid);
                if (!strcmp(systems[i],systemid)) {
                        g_strfreev(systems);
                        return TRUE;
index c54952d..e5ba000 100644 (file)
@@ -436,38 +436,87 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        if (src_codeset == NULL)
                src_codeset = CS_ISO_8859_1;
                
-       fprintf(dstfp, "MIME-Version: 1.0\r\n"
+       if (fprintf(dstfp, "MIME-Version: 1.0\r\n"
                        "Content-Type: text/plain; charset=%s\r\n"
                        "Content-Transfer-Encoding: 8bit\r\n"
                        "\r\n",
-                       src_codeset);
+                       src_codeset) < 0) {
+               FILE_OP_ERROR(fname, "fprintf");
+               privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               return NULL;
+       }
 
        /* Store any part before encrypted text */
        pos = strstr(textdata, begin_indicator);
        if (pos != NULL && (pos - textdata) > 0) {
-           fwrite(textdata, pos - textdata, 1, dstfp);
+           if (fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) {
+               FILE_OP_ERROR(fname, "fwrite");
+               privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               return NULL;
+           }
        }
        
-       fwrite(_("\n--- Start of PGP/Inline encrypted data ---\n"), 
+       if (fwrite(_("\n--- Start of PGP/Inline encrypted data ---\n"), 1,
                strlen(_("\n--- Start of PGP/Inline encrypted data ---\n")), 
-               1, dstfp);
+               dstfp) < strlen(_("\n--- Start of PGP/Inline encrypted data ---\n"))) {
+               FILE_OP_ERROR(fname, "fwrite");
+               privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               return NULL;
+       }
        chars = sgpgme_data_release_and_get_mem(plain, &len);
-       if (len > 0)
-               fwrite(chars, len, 1, dstfp);
-
+       if (len > 0) {
+               if (fwrite(chars, 1, len, dstfp) < len) {
+                       FILE_OP_ERROR(fname, "fwrite");
+                       privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+                       g_free(fname);
+                       gpgme_data_release(plain);
+                       gpgme_release(ctx);
+                       return NULL;
+               }
+       }
        /* Store any part after encrypted text */
-       fwrite(_("--- End of PGP/Inline encrypted data ---\n"), 
+       if (fwrite(_("--- End of PGP/Inline encrypted data ---\n"), 1,
                strlen(_("--- End of PGP/Inline encrypted data ---\n")), 
-               1, dstfp);
+               dstfp) < strlen(_("--- End of PGP/Inline encrypted data ---\n"))) {
+                       FILE_OP_ERROR(fname, "fwrite");
+                       privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+                       g_free(fname);
+                       gpgme_data_release(plain);
+                       gpgme_release(ctx);
+                       return NULL;
+       }
        if (pos != NULL) {
            pos = strstr(pos, end_indicator);
            if (pos != NULL && *pos != '\0') {
                pos += strlen(end_indicator);
-               fwrite(pos, strlen(pos), 1, dstfp);
+               if (fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) {
+                       FILE_OP_ERROR(fname, "fwrite");
+                       privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+                       g_free(fname);
+                       gpgme_data_release(plain);
+                       gpgme_release(ctx);
+                       return NULL;
+               }
            }
        }
 
-       fclose(dstfp);
+       if (fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "fclose");
+               privacy_set_error(_("Couldn't close decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               return NULL;
+       }
        
        parseinfo = procmime_scan_file(fname);
        g_free(fname);
index 30d7f95..2b7d106 100644 (file)
@@ -348,12 +348,37 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
                return NULL;
        }
 
-       fprintf(dstfp, "MIME-Version: 1.0\n");
+       if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
+               FILE_OP_ERROR(fname, "fprintf");
+               privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               debug_print("can't open!\n");
+               return NULL;
+       }
 
        chars = sgpgme_data_release_and_get_mem(plain, &len);
-       if (len > 0)
-               fwrite(chars, len, 1, dstfp);
-       fclose(dstfp);
+       if (len > 0) {
+               if (fwrite(chars, 1, len, dstfp) < len) {
+                       FILE_OP_ERROR(fname, "fwrite");
+                       privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
+                       g_free(fname);
+                       gpgme_data_release(plain);
+                       gpgme_release(ctx);
+                       debug_print("can't open!\n");
+                       return NULL;
+               }
+       }
+       if (fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "fclose");
+               privacy_set_error(_("Couldn't close decrypted file %s"), fname);
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               debug_print("can't open!\n");
+               return NULL;
+       }
 
        parseinfo = procmime_scan_file(fname);
        g_free(fname);
index b591061..a25d058 100644 (file)
@@ -526,9 +526,11 @@ void spamassassin_save_config(void)
                prefs_file_close_revert(pfile);
                return;
        }
-       fprintf(pfile->fp, "\n");
-
-       prefs_file_close(pfile);
+        if (fprintf(pfile->fp, "\n") < 0) {
+               FILE_OP_ERROR(rcpath, "fprintf");
+               prefs_file_close_revert(pfile);
+       } else
+               prefs_file_close(pfile);
 }
 
 gboolean spamassassin_check_username(void)
index 77f8e07..3c8427d 100644 (file)
@@ -172,6 +172,9 @@ static void save_trayicon_prefs(PrefsPage *page)
           prefs_file_close_revert(pref_file);
           return;
         }
-        fprintf(pref_file->fp, "\n");
-        prefs_file_close(pref_file);
+        if (fprintf(pref_file->fp, "\n") < 0) {
+               FILE_OP_ERROR(rc_file_path, "fprintf");
+               prefs_file_close_revert(pref_file);
+       } else
+               prefs_file_close(pref_file);
 }
index 41e374c..7aad105 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -734,8 +734,12 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
                FILE_OP_ERROR(file, "chmod");
 
        if (prefix != NULL) {
-               fprintf(fp, "%s", prefix);
-               fprintf(fp, "\n");
+               if (fprintf(fp, "%s\n", prefix) < 0) {
+                       FILE_OP_ERROR(file, "fprintf");
+                       fclose(fp);
+                       g_unlink(file);
+                       return -1;
+               }
        }
        
        /* +------------------+----------------+--------------------------+ *
index 59eae5f..f89f6b7 100644 (file)
@@ -261,10 +261,13 @@ const gchar *procmime_mimeinfo_get_parameter(MimeInfo *mimeinfo, const gchar *na
                        /* this is flowed */                                    \
                        if (delsp)                                              \
                                lastline[llen-1] = '\0';                        \
-                       fputs(lastline, outfp);                                 \
+                       if (fputs(lastline, outfp) == EOF)                      \
+                               err = TRUE;                                     \
                } else {                                                        \
-                       fputs(lastline, outfp);                                 \
-                       fputs("\n", outfp);                                     \
+                       if (fputs(lastline, outfp) == EOF)                      \
+                               err = TRUE;                                     \
+                       if (fputs("\n", outfp) == EOF)                          \
+                               err = TRUE;                                     \
                }                                                               \
        }                                                                       \
        strcpy(lastline, buf);                                                  \
@@ -280,6 +283,8 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        gboolean tmp_file = FALSE;
        gboolean flowed = FALSE;
        gboolean delsp = FALSE; 
+       gboolean err = FALSE;
+
        EncodingType encoding = forced_encoding 
                                ? forced_encoding
                                : mimeinfo->encoding_type;
@@ -330,7 +335,8 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        len = qp_decode_line(buf);
                        buf[len]='\0';
                        if (!flowed) {
-                               fwrite(buf, 1, len, outfp);
+                               if (fwrite(buf, 1, len, outfp) < len)
+                                       err = TRUE;
                        } else {
                                FLUSH_LASTLINE();
                        }
@@ -362,16 +368,18 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        len = base64_decoder_decode(decoder, buf, outbuf);
                        if (len < 0 && !got_error) {
                                g_warning("Bad BASE64 content.\n");
-                               fwrite(_("[Error decoding BASE64]\n"),
+                               if (fwrite(_("[Error decoding BASE64]\n"),
                                        sizeof(gchar),
                                        strlen(_("[Error decoding BASE64]\n")),
-                                       tmpfp);
+                                       tmpfp) < strlen(_("[Error decoding BASE64]\n")))
+                                       g_warning("error decoding BASE64");
                                got_error = TRUE;
                                continue;
                        } else if (len >= 0) {
                                /* print out the error message only once 
                                 * per block */
-                               fwrite(outbuf, sizeof(gchar), len, tmpfp);
+                               if (fwrite(outbuf, sizeof(gchar), len, tmpfp) < len)
+                                       err = TRUE;
                                got_error = FALSE;
                        }
                }
@@ -381,7 +389,8 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        rewind(tmpfp);
                        while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
                                strcrchomp(buf);
-                               fputs(buf, outfp);
+                               if (fputs(buf, outfp) == EOF)
+                                       err = TRUE;
                        }
                        fclose(tmpfp);
                }
@@ -400,25 +409,33 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                                                g_warning("Bad UUENCODE content(%d)\n", len);
                                        break;
                                }
-                               fwrite(outbuf, sizeof(gchar), len, outfp);
+                               if (fwrite(outbuf, sizeof(gchar), len, outfp) < len)
+                                       err = TRUE;
                        } else
                                flag = TRUE;
                }
        } else {
                while ((ftell(infp) < readend) && (fgets(buf, sizeof(buf), infp) != NULL)) {
                        if (!flowed) {
-                               fputs(buf, outfp);
+                               if (fputs(buf, outfp) == EOF)
+                                       err = TRUE;
                        } else {
                                FLUSH_LASTLINE();
                        }
                }
                if (flowed)
                        FLUSH_LASTLINE();
+               if (err == TRUE)
+                       g_warning("write error");
        }
 
        fclose(outfp);
        fclose(infp);
 
+       if (err == TRUE) {
+               return FALSE;
+       }
+
        stat(tmpfilename, &statbuf);
        if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
                g_unlink(mimeinfo->data.filename);
@@ -441,6 +458,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
        gint len;
        gchar *tmpfilename;
        struct stat statbuf;
+       gboolean err = FALSE;
 
        if (mimeinfo->content == MIMECONTENT_EMPTY)
                return TRUE;
@@ -505,13 +523,17 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                    B64_LINE_SIZE, tmp_fp))
                       == B64_LINE_SIZE) {
                        base64_encode(outbuf, inbuf, B64_LINE_SIZE);
-                       fputs(outbuf, outfp);
-                       fputc('\n', outfp);
+                       if (fputs(outbuf, outfp) == EOF)
+                               err = TRUE;
+                       if (fputc('\n', outfp) == EOF)
+                               err = TRUE;
                }
                if (len > 0 && feof(tmp_fp)) {
                        base64_encode(outbuf, inbuf, len);
-                       fputs(outbuf, outfp);
-                       fputc('\n', outfp);
+                       if (fputs(outbuf, outfp) == EOF)
+                               err = TRUE;
+                       if (fputc('\n', outfp) == EOF)
+                               err = TRUE;
                }
 
                if (tmp_file) {
@@ -530,23 +552,31 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                
                                tmpbuf += sizeof("From ")-1;
                                
-                               fputs("=46rom ", outfp);
-                               fputs(tmpbuf, outfp);
-                       } else 
-                               fputs(outbuf, outfp);
+                               if (fputs("=46rom ", outfp) == EOF)
+                                       err = TRUE;
+                               if (fputs(tmpbuf, outfp) == EOF)
+                                       err = TRUE;
+                       } else {
+                               if (fputs(outbuf, outfp) == EOF)
+                                       err = TRUE;
+                       }
                }
        } else {
                gchar buf[BUFFSIZE];
 
                while (fgets(buf, sizeof(buf), infp) != NULL) {
                        strcrchomp(buf);
-                       fputs(buf, outfp);
+                       if (fputs(buf, outfp) == EOF)
+                               err = TRUE;
                }
        }
 
        fclose(outfp);
        fclose(infp);
 
+       if (err == TRUE)
+               return FALSE;
+
        if (mimeinfo->content == MIMECONTENT_FILE) {
                if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
                        g_unlink(mimeinfo->data.filename);
@@ -690,7 +720,7 @@ void renderer_write_config(void)
        gchar * rcpath;
        PrefFile *pfile;
        GList * cur;
-
+       int err = 0;
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
        
        if ((pfile = prefs_write_open(rcpath)) == NULL) {
@@ -704,13 +734,20 @@ void renderer_write_config(void)
        for (cur = renderer_list ; cur != NULL ; cur = cur->next) {
                struct ContentRenderer * renderer;
                renderer = cur->data;
-               fprintf(pfile->fp, "%s %s\n", renderer->content_type,
-                       renderer->renderer);
+               if (fprintf(pfile->fp, "%s %s\n", renderer->content_type,
+                       renderer->renderer) < 0) {
+                       err = TRUE;
+                       break;
+               }
        }
 
-       if (prefs_file_close(pfile) < 0) {
-               g_warning("failed to write configuration to file\n");
-               return;
+       if (!err) {
+               if (prefs_file_close(pfile) < 0) {
+                       g_warning("failed to write configuration to file\n");
+                       return;
+               }
+       } else {
+               prefs_file_close_revert(pfile);
        }
 }
 
@@ -724,7 +761,8 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
        struct ContentRenderer * renderer;
        GList * cur;
        gchar *tmpfile, *content_type;
-    
+       gboolean err = FALSE;
+
        g_return_val_if_fail(mimeinfo != NULL, NULL);
 
        if (!procmime_decode_content(mimeinfo))
@@ -785,8 +823,10 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                        
                        while ((count =
                                fread(buf, sizeof(char), sizeof(buf),
-                                     tmpfp)) > 0)
-                               fwrite(buf, sizeof(char), count, p);
+                                     tmpfp)) > 0) {
+                               if (fwrite(buf, sizeof(char), count, p) < count)
+                                       err = TRUE;
+                       }
                        pclose(p);
                }
                
@@ -799,7 +839,8 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                conv = conv_code_converter_new(src_codeset);
                parser = sc_html_parser_new(tmpfp, conv);
                while ((str = sc_html_parse(parser)) != NULL) {
-                       fputs(str, outfp);
+                       if (fputs(str, outfp) == EOF)
+                               err = TRUE;
                }
                sc_html_parser_destroy(parser);
                conv_code_converter_destroy(conv);
@@ -810,7 +851,8 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                conv = conv_code_converter_new(src_codeset);
                parser = ertf_parser_new(tmpfp, conv);
                while ((str = ertf_parse(parser)) != NULL) {
-                       fputs(str, outfp);
+                       if (fputs(str, outfp) == EOF)
+                               err = TRUE;
                }
                ertf_parser_destroy(parser);
                conv_code_converter_destroy(conv);
@@ -818,11 +860,13 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
                        str = conv_codeset_strdup(buf, src_codeset, CS_UTF_8);
                        if (str) {
-                               fputs(str, outfp);
+                               if (fputs(str, outfp) == EOF)
+                                       err = TRUE;
                                g_free(str);
                        } else {
                                conv_fail = TRUE;
-                               fputs(buf, outfp);
+                               if (fputs(buf, outfp) == EOF)
+                                       err = TRUE;
                        }
                }
        }
@@ -835,6 +879,11 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
        g_unlink(tmpfile);
        g_free(tmpfile);
 
+       if (err == TRUE) {
+               fclose(outfp);
+               return NULL;
+       }
+
        return outfp;
 }
 
@@ -2052,6 +2101,7 @@ typedef struct _ParametersData {
        FILE *fp;
        guint len;
        guint ascii_only;
+       gint error;
 } ParametersData;
 
 static void write_parameters(gpointer key, gpointer value, gpointer user_data)
@@ -2142,17 +2192,25 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
        
        if (buf->str && strlen(buf->str)) {
                if (pdata->len + strlen(buf->str) + 2 > 76) {
-                       fprintf(pdata->fp, ";\n %s", buf->str);
+                       if (fprintf(pdata->fp, ";\n %s", buf->str) < 0)
+                               pdata->error = TRUE;
                        pdata->len = strlen(buf->str) + 1;
                } else {
-                       fprintf(pdata->fp, "; %s", buf->str);
+                       if (fprintf(pdata->fp, "; %s", buf->str) < 0)
+                               pdata->error = TRUE;
                        pdata->len += strlen(buf->str) + 2;
                }
        }
        g_string_free(buf, TRUE);
 }
 
-void procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
+#define TRY(func) { \
+       if (!(func)) { \
+               return -1; \
+       } \
+}
+
+int procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
 {
        struct TypeTable *type_table;
        ParametersData *pdata = g_new0(ParametersData, 1);
@@ -2160,33 +2218,41 @@ void procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
        
        pdata->fp = fp;
        pdata->ascii_only = FALSE;
-
+       pdata->error = FALSE;
        for (type_table = mime_type_table; type_table->str != NULL; type_table++)
                if (mimeinfo->type == type_table->type) {
                        gchar *buf = g_strdup_printf(
                                "Content-Type: %s/%s", type_table->str, mimeinfo->subtype);
-                       fprintf(fp, "%s", buf);
+                       if (fprintf(fp, "%s", buf) < 0) {
+                               g_free(buf);
+                               g_free(pdata);
+                               return -1;
+                       }
                        pdata->len = strlen(buf);
                        pdata->ascii_only = TRUE;
                        g_free(buf);
                        break;
                }
        g_hash_table_foreach(mimeinfo->typeparameters, write_parameters, pdata);
+       if (pdata->error == TRUE) {
+               g_free(pdata);
+               return -1;
+       }
        g_free(pdata);
 
-       fprintf(fp, "\n");
+       TRY(fprintf(fp, "\n") >= 0);
 
        if (mimeinfo->encoding_type != ENC_UNKNOWN)
-               fprintf(fp, "Content-Transfer-Encoding: %s\n", procmime_get_encoding_str(mimeinfo->encoding_type));
+               TRY(fprintf(fp, "Content-Transfer-Encoding: %s\n", procmime_get_encoding_str(mimeinfo->encoding_type)) >= 0);
 
        if (mimeinfo->description != NULL)
-               fprintf(fp, "Content-Description: %s\n", mimeinfo->description);
+               TRY(fprintf(fp, "Content-Description: %s\n", mimeinfo->description) >= 0);
 
        if (mimeinfo->id != NULL)
-               fprintf(fp, "Content-ID: %s\n", mimeinfo->id);
+               TRY(fprintf(fp, "Content-ID: %s\n", mimeinfo->id) >= 0);
 
        if (mimeinfo->location != NULL)
-               fprintf(fp, "Content-Location: %s\n", mimeinfo->location);
+               TRY(fprintf(fp, "Content-Location: %s\n", mimeinfo->location) >= 0);
 
        if (mimeinfo->disposition != DISPOSITIONTYPE_UNKNOWN) {
                ParametersData *pdata = g_new0(ParametersData, 1);
@@ -2198,19 +2264,29 @@ void procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
                else
                        buf = g_strdup("Content-Disposition: unknown");
 
-               fprintf(fp, "%s", buf);
+               if (fprintf(fp, "%s", buf) < 0) {
+                       g_free(buf);
+                       g_free(pdata);
+                       return -1;
+               }
                pdata->len = strlen(buf);
                g_free(buf);
 
                pdata->fp = fp;
                pdata->ascii_only = FALSE;
-
+               pdata->error = FALSE;
                g_hash_table_foreach(mimeinfo->dispositionparameters, write_parameters, pdata);
+               if (pdata->error == TRUE) {
+                       g_free(pdata);
+                       return -1;
+               }
                g_free(pdata);
-               fprintf(fp, "\n");
+               TRY(fprintf(fp, "\n") >= 0);
        }
 
-       fprintf(fp, "\n");
+       TRY(fprintf(fp, "\n") >= 0);
+       
+       return 0;
 }
 
 static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
@@ -2220,6 +2296,7 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
        MimeInfo *child;
        gchar buf[BUFFSIZE];
        gboolean skip = FALSE;;
+       size_t len;
 
        debug_print("procmime_write_message_rfc822\n");
 
@@ -2247,17 +2324,23 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
                                skip = TRUE;
                                continue;
                        }
-                       fwrite(buf, sizeof(gchar), strlen(buf), fp);
+                       len = strlen(buf);
+                       if (fwrite(buf, sizeof(gchar), len, fp) < len) {
+                               g_warning("failed to dump %d bytes from file", len);
+                               fclose(infp);
+                               return -1;
+                       }
                        skip = FALSE;
                }
                fclose(infp);
                break;
 
        case MIMECONTENT_MEM:
-               fwrite(mimeinfo->data.mem, 
-                               sizeof(gchar), 
-                               strlen(mimeinfo->data.mem), 
-                               fp);
+               len = strlen(mimeinfo->data.mem);
+               if (fwrite(mimeinfo->data.mem, sizeof(gchar), len, fp) < len) {
+                       g_warning("failed to dump %d bytes from mem", len);
+                       return -1;
+               }
                break;
 
        default:
@@ -2269,8 +2352,12 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
                return -1;
 
        child = (MimeInfo *) childnode->data;
-       fprintf(fp, "Mime-Version: 1.0\n");
-       procmime_write_mime_header(child, fp);
+       if (fprintf(fp, "Mime-Version: 1.0\n") < 0) {
+               g_warning("failed to write mime version");
+               return -1;
+       }
+       if (procmime_write_mime_header(child, fp) < 0)
+               return -1;
        return procmime_write_mimeinfo(child, fp);
 }
 
@@ -2281,6 +2368,7 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
        gchar *boundary, *str, *str2;
        gchar buf[BUFFSIZE];
        gboolean firstboundary;
+       size_t len;
 
        debug_print("procmime_write_multipart\n");
 
@@ -2296,7 +2384,12 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
                while (fgets(buf, sizeof(buf), infp) == buf) {
                        if (IS_BOUNDARY(buf, boundary, strlen(boundary)))
                                break;
-                       fwrite(buf, sizeof(gchar), strlen(buf), fp);
+                       len = strlen(buf);
+                       if (fwrite(buf, sizeof(gchar), len, fp) < len) {
+                               g_warning("failed to write %d", len);
+                               fclose(infp);
+                               return -1;
+                       }
                }
                fclose(infp);
                break;
@@ -2306,7 +2399,12 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
                if (((str2 = strstr(str, boundary)) != NULL) && ((str2 - str) >= 2) &&
                    (*(str2 - 1) == '-') && (*(str2 - 2) == '-'))
                        *(str2 - 2) = '\0';
-               fwrite(str, sizeof(gchar), strlen(str), fp);
+               len = strlen(str);
+               if (fwrite(str, sizeof(gchar), len, fp) < len) {
+                       g_warning("failed to write %d from mem", len);
+                       g_free(str);
+                       return -1;
+               }
                g_free(str);
                break;
 
@@ -2322,16 +2420,18 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
                if (firstboundary)
                        firstboundary = FALSE;
                else
-                       fprintf(fp, "\n");
-               fprintf(fp, "--%s\n", boundary);
+                       TRY(fprintf(fp, "\n") >= 0);
+                       
+               TRY(fprintf(fp, "--%s\n", boundary) >= 0);
 
-               procmime_write_mime_header(child, fp);
+               if (procmime_write_mime_header(child, fp) < 0)
+                       return -1;
                if (procmime_write_mimeinfo(child, fp) < 0)
                        return -1;
 
                childnode = g_node_next_sibling(childnode);
        }       
-       fprintf(fp, "\n--%s--\n", boundary);
+       TRY(fprintf(fp, "\n--%s--\n", boundary) >= 0);
 
        return 0;
 }
@@ -2339,7 +2439,7 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
 gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
 {
        FILE *infp;
-
+       size_t len;
        debug_print("procmime_write_mimeinfo\n");
 
        if (G_NODE_IS_LEAF(mimeinfo->node)) {
@@ -2354,10 +2454,9 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
                        return 0;
 
                case MIMECONTENT_MEM:
-                       fwrite(mimeinfo->data.mem, 
-                                       sizeof(gchar), 
-                                       strlen(mimeinfo->data.mem), 
-                                       fp);
+                       len = strlen(mimeinfo->data.mem);
+                       if (fwrite(mimeinfo->data.mem, sizeof(gchar), len, fp) < len)
+                               return -1;
                        return 0;
 
                default:
index aaf9f65..19336b2 100644 (file)
@@ -1080,7 +1080,7 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline)
        FILE *tmpfp, *prfp;
        gchar buf[1024];
        gchar *p;
-
+       int r;
        g_return_if_fail(msginfo);
 
        if (procmime_msginfo_is_encrypted(msginfo))
@@ -1102,17 +1102,17 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline)
                return;
        }
 
-       if (msginfo->date) fprintf(prfp, "Date: %s\n", msginfo->date);
-       if (msginfo->from) fprintf(prfp, "From: %s\n", msginfo->from);
-       if (msginfo->to)   fprintf(prfp, "To: %s\n", msginfo->to);
-       if (msginfo->cc)   fprintf(prfp, "Cc: %s\n", msginfo->cc);
+       if (msginfo->date) r = fprintf(prfp, "Date: %s\n", msginfo->date);
+       if (msginfo->from) r = fprintf(prfp, "From: %s\n", msginfo->from);
+       if (msginfo->to)   r = fprintf(prfp, "To: %s\n", msginfo->to);
+       if (msginfo->cc)   r = fprintf(prfp, "Cc: %s\n", msginfo->cc);
        if (msginfo->newsgroups)
-               fprintf(prfp, "Newsgroups: %s\n", msginfo->newsgroups);
-       if (msginfo->subject) fprintf(prfp, "Subject: %s\n", msginfo->subject);
+               r = fprintf(prfp, "Newsgroups: %s\n", msginfo->newsgroups);
+       if (msginfo->subject) r = fprintf(prfp, "Subject: %s\n", msginfo->subject);
        fputc('\n', prfp);
 
        while (fgets(buf, sizeof(buf), tmpfp) != NULL)
-               fputs(buf, prfp);
+               r = fputs(buf, prfp);
 
        fclose(prfp);
        fclose(tmpfp);
index 7e575c1..14d4778 100644 (file)
@@ -588,34 +588,47 @@ void toolbar_save_config_file(ToolbarType source)
 
        fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
        pfile = prefs_write_open(fileSpec);
-       g_free( fileSpec );
        if( pfile ) {
                fp = pfile->fp;
-               fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
+               if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
+                       goto fail;
 
-               fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
+               if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
+                       goto fail;
 
                for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
                        ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
                        
                        if (toolbar_item->index != A_SEPARATOR) {
-                               fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
+                               if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
                                        TOOLBAR_TAG_ITEM, 
                                        TOOLBAR_ICON_FILE, toolbar_item->file,
-                                       TOOLBAR_ICON_TEXT);
-                               xml_file_put_escape_str(fp, toolbar_item->text);
-                               fprintf(fp, "\" %s=\"%s\"/>\n",
+                                       TOOLBAR_ICON_TEXT) < 0)
+                                       goto fail;
+                               if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
+                                       goto fail;
+                               if (fprintf(fp, "\" %s=\"%s\"/>\n",
                                        TOOLBAR_ICON_ACTION, 
-                                       toolbar_ret_text_from_val(toolbar_item->index));
+                                       toolbar_ret_text_from_val(toolbar_item->index)) < 0)
+                                       goto fail;
                        } else {
-                               fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR); 
+                               if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
+                                       goto fail;
                        }
                }
 
-               fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
+               if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
+                       goto fail;
        
+               g_free( fileSpec );
                if (prefs_file_close (pfile) < 0 ) 
                        g_warning("failed to write toolbar configuration to file\n");
+               return;
+               
+fail:
+               FILE_OP_ERROR(fileSpec, "fprintf");
+               g_free( fileSpec );
+               prefs_file_close_revert (pfile);
        } else
                g_warning("failed to open toolbar configuration file for writing\n");
 }