master 24.51
John Wiseman 1 year ago
parent 46adaeaa05
commit f2ca80333a

@ -36,14 +36,14 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
struct AGWHeader struct AGWHeader
{ {
int Port; unsigned int Port;
unsigned char DataKind; unsigned char DataKind;
unsigned char filler2; unsigned char filler2;
unsigned char PID; unsigned char PID;
unsigned char filler3; unsigned char filler3;
unsigned char callfrom[10]; unsigned char callfrom[10];
unsigned char callto[10]; unsigned char callto[10];
int DataLength; unsigned int DataLength;
int reserved; int reserved;
}; };
@ -1063,6 +1063,8 @@ int AGWDataSocket_Read(struct AGWSocketConnectionInfo * sockptr, SOCKET sock)
{ {
if (DataLength > 35)// A header if (DataLength > 35)// A header
{ {
struct AGWHeader * AGW = &sockptr->AGWRXHeader;
i=recv(sock,(char *)&sockptr->AGWRXHeader, 36, 0); i=recv(sock,(char *)&sockptr->AGWRXHeader, 36, 0);
if (i == SOCKET_ERROR) if (i == SOCKET_ERROR)
@ -1075,6 +1077,16 @@ int AGWDataSocket_Read(struct AGWSocketConnectionInfo * sockptr, SOCKET sock)
sockptr->MsgDataLength = sockptr->AGWRXHeader.DataLength; sockptr->MsgDataLength = sockptr->AGWRXHeader.DataLength;
// Validate packet to protect against accidental (or malicious!) connects from a non-agw application
if (AGW->Port > 64 || AGW->filler2 != 0 || AGW->filler3 != 0 || AGW->DataLength > 400)
{
Debugprintf("Corrupt AGW Packet Received");
AGWDataSocket_Disconnect(sockptr);
return 0;
}
if (sockptr->MsgDataLength > 500) if (sockptr->MsgDataLength > 500)
OutputDebugString("Corrupt AGW message"); OutputDebugString("Corrupt AGW message");

@ -405,41 +405,20 @@ int SendHeader(char * Reply, char * Key)
void ConvertTitletoUTF8(WebMailInfo * WebMail, char * Title, char * UTF8Title, int Len) void ConvertTitletoUTF8(WebMailInfo * WebMail, char * Title, char * UTF8Title, int Len)
{ {
if (WebIsUTF8(Title, (int)strlen(Title)) == FALSE) Len = strlen(Title);
{
// With Windows it is simple - convert using current codepage
// I think the only reliable way is to convert to unicode and back
int origlen = (int)strlen(Title) + 1;
#ifdef WIN32
WCHAR BufferW[128];
int wlen;
int len = origlen;
wlen = MultiByteToWideChar(CP_ACP, 0, Title, len, BufferW, origlen * 2);
len = WideCharToMultiByte(CP_UTF8, 0, BufferW, wlen, UTF8Title, origlen * 2, NULL, NULL);
#else
size_t left = Len - 1;
size_t len = origlen;
iconv_t * icu = WebMail->iconv_toUTF8;
if (WebMail->iconv_toUTF8 == NULL)
icu = WebMail->iconv_toUTF8 = iconv_open("UTF-8//IGNORE", "CP1252");
if (icu == (iconv_t)-1) if (WebIsUTF8(Title, Len) == FALSE)
{ {
strcpy(UTF8Title, Title); int code = TrytoGuessCode(Title, Len);
WebMail->iconv_toUTF8 = NULL;
return;
}
char * orig = UTF8Title;
iconv(icu, NULL, NULL, NULL, NULL); // Reset State Machine if (code == 437)
iconv(icu, &Title, &len, (char ** __restrict__)&UTF8Title, &left); Len = Convert437toUTF8(Title, Len, UTF8Title);
else if (code == 1251)
Len = Convert1251toUTF8(Title, Len, UTF8Title);
else
Len = Convert1252toUTF8(Title, Len, UTF8Title);
#endif UTF8Title[Len] = 0;
} }
else else
strcpy(UTF8Title, Title); strcpy(UTF8Title, Title);

@ -1142,6 +1142,7 @@
// Log Our HA when checking for flood bulls (45) // Log Our HA when checking for flood bulls (45)
// Semaphore calls to SaveConfig // Semaphore calls to SaveConfig
// Include SERVIC as valid from call (for Winlink Service messages) (49) // Include SERVIC as valid from call (for Winlink Service messages) (49)
// Attempt to detect line draw characters in Webmail (50)
#include "bpqmail.h" #include "bpqmail.h"
#include "winstdint.h" #include "winstdint.h"

@ -1233,6 +1233,7 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
// Fix possible crash if MQTT not in use (47) // Fix possible crash if MQTT not in use (47)
// Add optional ATTACH time limit for VARA (48) // Add optional ATTACH time limit for VARA (48)
// API format fixes (48) // API format fixes (48)
// AGWAPI Add protection against accidental connects from a non-agw application (50)
#define CKernel #define CKernel

@ -2656,6 +2656,7 @@ VOID ProcessPOP3ServerMessage(SocketConn * sockptr, char * Buffer, int Len)
// Must be some other coding // Must be some other coding
int code = TrytoGuessCode(msgbytes, Len); int code = TrytoGuessCode(msgbytes, Len);
UCHAR * UTF = malloc(Len * 3); UCHAR * UTF = malloc(Len * 3);
if (code == 437) if (code == 437)

@ -10,8 +10,8 @@
#endif #endif
#define KVers 6,0,24,49 #define KVers 6,0,24,50
#define KVerstring "6.0.24.49\0" #define KVerstring "6.0.24.50\0"
#ifdef CKernel #ifdef CKernel

@ -1246,63 +1246,25 @@ int ViewWebMailMessage(struct HTTPConnectionInfo * Session, char * Reply, int Nu
User->Total.MsgsSent[Index] ++; User->Total.MsgsSent[Index] ++;
// User->Total.BytesForwardedOut[Index] += Length; // User->Total.BytesForwardedOut[Index] += Length;
// if body not UTF-8, convert it // if body not UTF-8, convert it
if (WebIsUTF8(MsgBytes, msgLen) == FALSE) if (WebIsUTF8(MsgBytes, msgLen) == FALSE)
{ {
// With Windows it is simple - convert using current codepage int code = TrytoGuessCode(MsgBytes, msgLen);
// I think the only reliable way is to convert to unicode and back
size_t origlen = msgLen + 1;
UCHAR * BufferB = malloc(2 * origlen);
#ifdef WIN32
WCHAR * BufferW = malloc(2 * origlen);
int wlen;
int len = (int)origlen;
wlen = MultiByteToWideChar(CP_ACP, 0, MsgBytes, len, BufferW, (int)(origlen * 2));
len = WideCharToMultiByte(CP_UTF8, 0, BufferW, wlen, BufferB, (int)(origlen * 2), NULL, NULL);
free(Save); UCHAR * UTF = malloc(msgLen * 3);
Save = MsgBytes = BufferB;
free(BufferW);
msgLen = len - 1; // exclude NULL
#else
size_t left = 2 * msgLen;
size_t outbuflen = left;
size_t len = msgLen + 1; // include null
int ret;
UCHAR * BufferBP = BufferB;
char * orig = MsgBytes;
MsgBytes[msgLen] = 0;
iconv_t * icu = Session->WebMail->iconv_toUTF8; if (code == 437)
msgLen = Convert437toUTF8(MsgBytes, msgLen, UTF);
if (icu == NULL) else if (code == 1251)
icu = Session->WebMail->iconv_toUTF8 = iconv_open("UTF-8//IGNORE", "CP1252"); msgLen = Convert1251toUTF8(MsgBytes, msgLen, UTF);
if (icu == (iconv_t) -1)
{
Session->WebMail->iconv_toUTF8 = NULL;
strcpy(BufferB, MsgBytes);
}
else else
{ msgLen = Convert1252toUTF8(MsgBytes, msgLen, UTF);
iconv(icu, NULL, NULL, NULL, NULL); // Reset State Machine
ret = iconv(icu, &MsgBytes, &len, (char ** __restrict__)&BufferBP, &left); free(MsgBytes);
} Save = MsgBytes = UTF;
// left is next location to write, so length written is outbuflen - left MsgBytes[msgLen] = 0;
// add a null in case iconv didn't complete comversion
BufferB[outbuflen - left] = 0;
free(Save);
Save = MsgBytes = BufferB;
msgLen = strlen(MsgBytes);
#endif
} }
// ptr += sprintf(ptr, "%s", MsgBytes); // ptr += sprintf(ptr, "%s", MsgBytes);

@ -548,8 +548,8 @@ int TrytoGuessCode(unsigned char * Char, int Len)
if (Above127 == 0) // DOesn't really matter! if (Above127 == 0) // DOesn't really matter!
return 1252; return 1252;
if (Above127 == LineDraw) if (LineDraw > ((Above127 * 9) / 10))
return 437; // If only Line Draw chars, assume line draw return 437; // If mainly Line Draw chars, assume line draw
// If mainly below 128, it is probably Latin if mainly above, probably Cyrillic // If mainly below 128, it is probably Latin if mainly above, probably Cyrillic

Loading…
Cancel
Save

Powered by TurnKey Linux.