summaryrefslogtreecommitdiff
path: root/WebMail.c
diff options
context:
space:
mode:
Diffstat (limited to 'WebMail.c')
-rw-r--r--WebMail.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/WebMail.c b/WebMail.c
index a97b9bf..f7ba786 100644
--- a/WebMail.c
+++ b/WebMail.c
@@ -27,6 +27,7 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
#ifdef WIN32
//#include "C:\Program Files (x86)\GnuWin32\include\iconv.h"
+ #define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#else
#include <iconv.h>
#include <dirent.h>
@@ -1467,6 +1468,15 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
char Type[64] = "Content-Type: text/html\r\n";
UndoTransparency(FN);
+
+ // protect against malicious access
+
+ if (strstr(FN, ".."))
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
+ }
+
ext = strchr(FN, '.');
sprintf(MsgFile, "%s/%s", BPQDirectory, FN);
@@ -1480,6 +1490,14 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
return;
}
+ FileSize = STAT.st_size;
+
+ if (FileSize > 200000)
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 400 File too long\r\nContent-Length: 15\r\n\r\nFile too long\r\n");
+ return;
+ }
+
hFile = fopen(MsgFile, "rb");
if (hFile == 0)
@@ -1488,7 +1506,7 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
return;
}
- FileSize = STAT.st_size;
+
MsgBytes = malloc(FileSize + 1);
ReadLen = fread(MsgBytes, 1, FileSize, hFile);
@@ -1543,8 +1561,24 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
char * ext;
char Type[64] = "Content-Type: text/html\r\n";
-
UndoTransparency(FN);
+
+ // protect against malicious access
+
+ if (strstr(FN, ".."))
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
+ }
+
+ // I'm pretty sure this should only be used for form sets, so name should start Standard or Local
+
+ if (_memicmp(FN, "Local", 5) != 0 && (_memicmp(FN, "Standard", 9) != 0))
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
+ }
+
ext = strchr(FN, '.');
sprintf(MsgFile, "%s/%s", BPQDirectory, FN);
@@ -1558,6 +1592,14 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
return;
}
+ FileSize = STAT.st_size;
+
+ if (FileSize > 200000)
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 400 File too big\r\nContent-Length: 15\r\n\r\nFile too long\r\n");
+ return;
+ }
+
hFile = fopen(MsgFile, "rb");
if (hFile == 0)
@@ -1566,7 +1608,6 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
return;
}
- FileSize = STAT.st_size;
MsgBytes = malloc(FileSize + 1);
ReadLen = fread(MsgBytes, 1, FileSize, hFile);
@@ -3534,8 +3575,6 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
sprintf(FormDir, "WMFile/%s/%s/", Dir->FormSet, Dir->DirName);
-
-
if (Form == NULL)
{
// Not found - just display as normal message