[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    possible fix for deadLetter
From:       Daniel Naber <dnaber () mini ! gt ! owl ! de>
Date:       2000-02-27 22:09:59
[Download RAW message or body]

Hi,

currently deadLetter in kmcomposewin creates a file with read/write
permission for everybody (and it has some small bugs). I wanted to 
fix that, see attachment.

Problem is (and that was a probem before) that the data written
might be trashed because of the crash. Is there a way to get around
that? For exmaple, I added fw = NULL; in slotCut() to make a crash.
dead.letter gets written, but it has some binary trash in it at the beginning
of msgStr.

Also, with this new function the composewindow stays open when kmail
crashes. With the old code, it didn't. Maybe there's some stupid mistake
(or coincidence?), since in the end this is C code and I don't know C very
good.

Can someone please test this and apply if it's okay? (Sorry, my kmail
source isn't up to date so you might get warnings when you apply
the patch - I will update soon).

Regards
 Daniel

["dead-letter-permissions.diff" (text/plain)]

--- kmcomposewin.cpp.bak	Sun Feb 27 16:26:58 2000
+++ kmcomposewin.cpp	Sun Feb 27 23:09:20 2000
@@ -60,6 +60,7 @@
 #include <errno.h>
 #include <klocale.h>
 #include <ktempfile.h>
+#include <fcntl.h>
 
 #if defined CHARSETS
 #include <kcharsets.h>
@@ -349,28 +350,31 @@
 //-----------------------------------------------------------------------------
 void KMComposeWin::deadLetter(void)
 {
-  FILE* fh;
-  char fname[128];
+  int fd;
   const char* msgStr;
-
   if (!mMsg) return;
-
   // This method is called when KMail crashed, so we better use as
   // basic functions as possible here.
   applyChanges();
   msgStr = mMsg->asString();
-
-  sprintf(fname,"%s/dead.letter",getenv("HOME"));
-  fh = fopen(fname,"a");
-  if (fh)
+  QString fname = getenv("HOME");
+  fname += "/dead.letter";
+  // Security: the file is created in the user's home directory, which
+  // might be readable by other users. So the file only gets read/write
+  // permissions for the user himself. Note that we create the file with
+  // correct permissions, we do not set them after creating the file!
+  // (dnaber, 2000-02-27):
+  fd = open(fname, O_CREAT|O_APPEND|O_WRONLY, S_IWRITE|S_IREAD);
+  if (fd != -1)
   {
-    fwrite("From ???@??? Mon Jan 01 00:00:00 1997\n", 19, 1, fh);
-    fwrite(msgStr, strlen(msgStr), 1, fh);
-    fwrite("\n", 1, 1, fh);
-    fclose(fh);
+    const char* startStr = "From ???@??? Mon Jan 01 00:00:00 1997\n";
+    write(fd, startStr, strlen(startStr));
+    write(fd, msgStr, strlen(msgStr));
+    write(fd, "\n", 1);
+    close(fd);
     fprintf(stderr,"appending message to ~/dead.letter\n");
   }
-  else perror("cannot open ~/dead.letter");
+  else perror("cannot open ~/dead.letter for saving the current message");
 }
 
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic