From c3c371677d5355788cf200b051fd59289807f14d Mon Sep 17 00:00:00 2001 From: gustavf Date: Fri, 11 Feb 2000 09:46:15 +0000 Subject: [PATCH] No longer put complete filename relative to / in the HTML-code when attaching files. This was a security bummer. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@208 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/smtp.php | 10 +++++----- src/compose.php | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/functions/smtp.php b/functions/smtp.php index 2a397f28..d6bf6993 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -21,10 +21,10 @@ // Attach the files that are due to be attached function attachFiles ($fp) { - global $attachments; + global $attachments, $attachment_dir; while (list($localname, $remotename) = each($attachments)) { - $fileinfo = fopen ($localname.".info", "r"); + $fileinfo = fopen ($attachment_dir.$localname.".info", "r"); $filetype = fgets ($fileinfo, 8192); fclose ($fileinfo); $filetype = trim ($filetype); @@ -36,13 +36,13 @@ fputs ($fp, "Content-Disposition: attachment; filename=\"$remotename\"\n"); fputs ($fp, "Content-Transfer-Encoding: base64\n\n"); - $file = fopen ($localname, "r"); + $file = fopen ($attachment_dir.$localname, "r"); while ($tmp = fread($file, 57)) fputs ($fp, chunk_split(base64_encode($tmp))); fclose ($file); - unlink ($localname); - unlink ($localname.".info"); + unlink ($attachment_dir.$localname); + unlink ($attachment_dir.$localname.".info"); } } diff --git a/src/compose.php b/src/compose.php index d9ea51ea..746c10a1 100644 --- a/src/compose.php +++ b/src/compose.php @@ -286,30 +286,33 @@ } } else if (isset($attach)) { $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy"); - $localfilename = $attachment_dir.$localfilename; + $localfilename = $localfilename; // Put the file in a better place error_reporting(0); // Rename will produce error output if it fails - if (!rename($attachfile, $localfilename)) { - if (!copy($attachfile, $localfilename)) { + if (!rename($attachfile, $attachment_dir.$localfilename)) { + if (!copy($attachfile, $attachment_dir.$localfilename)) { plain_error_message(_("Could not move/copy file. File not attached")); + $failed = true; } } // If it still exists, PHP will remove the original file - // Write information about the file - $fp = fopen ($localfilename.".info", "w"); - fputs ($fp, "$attachfile_type\n$attachfile_name\n"); - fclose ($fp); + if (!$failed) { + // Write information about the file + $fp = fopen ($attachment_dir.$localfilename.".info", "w"); + fputs ($fp, "$attachfile_type\n$attachfile_name\n"); + fclose ($fp); - $attachments[$localfilename] = $attachfile_name; + $attachments[$localfilename] = $attachfile_name; + } showInputForm(); } else if (isset($do_delete)) { while (list($key, $localname) = each($delete)) { array_splice ($attachments, $localname, 1); - unlink ($localname); - unlink ($localname.".info"); + unlink ($attachment_dir.$localname); + unlink ($attachment_dir.$localname.".info"); } showInputForm(); -- 2.25.1