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

List:       kmail-devel
Subject:    Re: possible fix for deadLetter
From:       Daniel Naber <dnaber () mini ! gt ! owl ! de>
Date:       2000-02-28 23:13:36
[Download RAW message or body]

On Mon, 28 Feb 2000, Waldo Bastian wrote:

> > don't know C very good.
> 
> Just use C++ code. 

I was just refering to the open/write/close, I guess it is okay to use these?

> Especially: msgStr = mMsg->asString() might cause problems because the 
> object to which the string belongs gets destructed and takes the string 
> with it. msgStr then points to this destructed string.

Thanks, I changed that and now it seems to work. New patch is attached.
Can anyone apply please if there are no further problems with it?

Regards
 Daniel

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

--- kmcomposewin.cpp.bak	Sun Feb 27 16:26:58 2000
+++ kmcomposewin.cpp	Tue Feb 29 00:11:27 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,29 @@
 //-----------------------------------------------------------------------------
 void KMComposeWin::deadLetter(void)
 {
-  FILE* fh;
-  char fname[128];
-  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 msgStr = mMsg->asString();
+  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):
+  int 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.latin1(), msgStr.length());		// TODO?: not unicode aware :-(
+    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