From 23de03a0c8bf8a564cc0442f49d050ed11e372b8 Mon Sep 17 00:00:00 2001 From: Dave Hibberd Date: Mon, 29 Jun 2026 11:36:57 +0100 Subject: New upstream version 6.0.25.33.1+repack --- WebMail.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'WebMail.c') 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 #include @@ -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 -- cgit v1.2.3