fixed security issues - fixes bug 1307 fixed unicode over network issues Modified: trunk/reactos/base/services/tcpsvcs/chargen.c Modified: trunk/reactos/base/services/tcpsvcs/daytime.c Modified: trunk/reactos/base/services/tcpsvcs/discard.c Modified: trunk/reactos/base/services/tcpsvcs/echo.c Modified: trunk/reactos/base/services/tcpsvcs/qotd.c Modified: trunk/reactos/base/services/tcpsvcs/skelserver.c Modified: trunk/reactos/base/services/tcpsvcs/tcpsvcs.c Modified: trunk/reactos/base/services/tcpsvcs/tcpsvcs.h _____
Modified: trunk/reactos/base/services/tcpsvcs/chargen.c --- trunk/reactos/base/services/tcpsvcs/chargen.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/chargen.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/chargen.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include "tcpsvcs.h" @@ -30,7 +30,7 @@ LogEvent(_T("Chargen: Connection shutdown failed\n"), 0, FALSE); RetVal = 1; } - + LogEvent(_T("Chargen: Terminating thread\n"), 0, FALSE); ExitThread(RetVal);
@@ -73,8 +73,8 @@ charIndex++; }
- Line[LINESIZ - 2] = L'\r'; - Line[LINESIZ - 1] = L'\n'; + Line[LINESIZ - 2] = '\r'; + Line[LINESIZ - 1] = '\n';
if (! SendLine(Sock, Line)) break; @@ -82,14 +82,14 @@ /* increment loop index to start printing from next char in ring */ loopIndex++; } - + if (bShutDown) return FALSE; else return TRUE; }
-BOOL SendLine(SOCKET Sock, TCHAR* Line) +BOOL SendLine(SOCKET Sock, char* Line) { INT RetVal; INT SentBytes; _____
Modified: trunk/reactos/base/services/tcpsvcs/daytime.c --- trunk/reactos/base/services/tcpsvcs/daytime.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/daytime.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/daytime.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include "tcpsvcs.h" @@ -13,14 +13,14 @@ { struct tm *newtime; time_t aclock; - TCHAR *pszTime; + CHAR *pszTime; DWORD RetVal = 0; SOCKET Sock = (SOCKET)Sock_; - + time(&aclock); newtime = localtime(&aclock); - pszTime = _tasctime(newtime); - + pszTime = asctime(newtime); + SendTime(Sock, pszTime);
LogEvent(_T("DayTime: Shutting connection down...\n"), 0, FALSE); @@ -31,17 +31,17 @@ LogEvent(_T("DayTime: Connection shutdown failed\n"), 0, FALSE); RetVal = 1; } - + LogEvent(_T("DayTime: Terminating thread\n"), 0, FALSE); ExitThread(RetVal); }
-BOOL SendTime(SOCKET Sock, TCHAR *time) +BOOL SendTime(SOCKET Sock, CHAR *time) { - INT StringSize = (INT)_tcsclen(time); - INT RetVal = send(Sock, time, sizeof(TCHAR) * StringSize, 0); - + INT StringSize = (INT)strlen(time); + INT RetVal = send(Sock, time, sizeof(CHAR) * StringSize, 0); + if (RetVal == SOCKET_ERROR) return FALSE;
_____
Modified: trunk/reactos/base/services/tcpsvcs/discard.c --- trunk/reactos/base/services/tcpsvcs/discard.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/discard.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/discard.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include "tcpsvcs.h" @@ -30,7 +30,7 @@ LogEvent(_T("Discard: Connection shutdown failed\n"), 0, FALSE); RetVal = 1; } - + LogEvent(_T("Discard: Terminating thread\n"), 0, FALSE); ExitThread(RetVal); } @@ -39,7 +39,7 @@
BOOL RecieveIncomingPackets(SOCKET Sock) { - TCHAR ReadBuffer[BUF]; + char ReadBuffer[BUF]; TCHAR buf[256]; INT ReadBytes;
@@ -53,7 +53,7 @@ } else if (ReadBytes == SOCKET_ERROR) { - _stprintf(buf, ("Socket Error: %d\n"), WSAGetLastError()); + _stprintf(buf, _T("Socket Error: %d\n"), WSAGetLastError()); LogEvent(buf, 0, TRUE); return FALSE; } _____
Modified: trunk/reactos/base/services/tcpsvcs/echo.c --- trunk/reactos/base/services/tcpsvcs/echo.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/echo.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/echo.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include "tcpsvcs.h" @@ -22,7 +22,7 @@ }
LogEvent(_T("Echo: Shutting connection down...\n"), 0, FALSE); - + if (ShutdownConnection(Sock, TRUE)) LogEvent(_T("Echo: Connection is down\n"), 0, FALSE); else @@ -30,7 +30,7 @@ LogEvent(_T("Echo: Connection shutdown failed\n"), 0, FALSE); RetVal = 1; } - + LogEvent(_T("Echo: Terminating thread\n"), 0, FALSE); ExitThread(RetVal); } @@ -39,7 +39,7 @@
BOOL EchoIncomingPackets(SOCKET Sock) { - TCHAR ReadBuffer[BUF]; + char ReadBuffer[BUF]; TCHAR buf[256]; // temp for holding LogEvent text INT Temp; INT ReadBytes; _____
Modified: trunk/reactos/base/services/tcpsvcs/qotd.c --- trunk/reactos/base/services/tcpsvcs/qotd.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/qotd.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,21 +4,21 @@
* FILE: /base/services/tcpsvcs/qotd.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include "tcpsvcs.h"
-#define QBUFSIZ 160 +#define QBUFSIZ 60
-LPCTSTR FilePath = _T("\drivers\etc\quotes"); +LPCTSTR FilePath = _T("\drivers\etc\quotes"); /* 19 chars */
DWORD WINAPI QotdHandler(VOID* Sock_) { FILE *fp; SOCKET Sock; - TCHAR Sys[MAX_PATH]; - TCHAR Quote[60][BUFSIZ]; // need to set this dynamically + TCHAR Sys[MAX_PATH + 20]; + char Quote[QBUFSIZ][BUFSIZ]; // need to set this dynamically INT QuoteToPrint; INT NumQuotes;
@@ -29,15 +29,15 @@ LogEvent(_T("QOTD: Getting system path failed.\n"), 0, TRUE); ExitThread(1); } - - _tcscat(Sys, FilePath);
+ _tcsncat(Sys, FilePath, _tcslen(FilePath)); + LogEvent(_T("QOTD: Opening quotes file\n"), 0, FALSE); - if ((fp = _tfopen(Sys, "r")) == NULL) + if ((fp = _tfopen(Sys, _T("r"))) == NULL) { - TCHAR buf[256]; + TCHAR buf[320];
- _stprintf(buf, _T("QOTD: Error opening quote file : %s\n"), Sys); + _sntprintf(buf, 320, _T("QOTD: Error opening quote file : %s\n"), Sys); LogEvent(buf, 0, TRUE); LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE); ExitThread(1); @@ -45,7 +45,8 @@
/* read all quotes in the file into an array */ NumQuotes = 0; - while (_fgetts(Quote[NumQuotes], QBUFSIZ, fp) != NULL) + while ((fgets(Quote[NumQuotes], QBUFSIZ, fp) != NULL) && + (NumQuotes != QBUFSIZ)) NumQuotes++;
LogEvent(_T("QOTD: Closing quotes file\n"), 0, FALSE); @@ -68,21 +69,20 @@ LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE); ExitThread(1); } - + LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE); ExitThread(0);
- //return Retval; }
-BOOL SendQuote(SOCKET Sock, TCHAR* Quote) +BOOL SendQuote(SOCKET Sock, char* Quote) { INT StringSize; INT RetVal;
- StringSize = (INT)_tcsclen(Quote); - RetVal = send(Sock, Quote, sizeof(TCHAR) * StringSize, 0); + StringSize = (INT)strlen(Quote); + RetVal = send(Sock, Quote, sizeof(char) * StringSize, 0);
if (RetVal == SOCKET_ERROR) return FALSE; _____
Modified: trunk/reactos/base/services/tcpsvcs/skelserver.c --- trunk/reactos/base/services/tcpsvcs/skelserver.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/skelserver.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/skelserver.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include "tcpsvcs.h" @@ -24,7 +24,7 @@ ListeningSocket = SetUpListener(htons(pServices->Port)); if (ListeningSocket == INVALID_SOCKET) { - LogEvent("Socket error when setting up listener\n", 0, TRUE); + LogEvent(_T("Socket error when setting up listener\n"), 0, TRUE); return 3; }
@@ -131,7 +131,7 @@ }
WaitForSingleObject(hThread, INFINITE); - + CloseHandle(hThread); } else _____
Modified: trunk/reactos/base/services/tcpsvcs/tcpsvcs.c --- trunk/reactos/base/services/tcpsvcs/tcpsvcs.c 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/tcpsvcs.c 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/tcpsvcs.c * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */ /* * TODO: @@ -31,7 +31,7 @@ BOOL bShutDown = FALSE; BOOL bPause = FALSE;
-LPCTSTR LogFileName = "\tcpsvcs_log.log"; +LPCTSTR LogFileName = _T("\tcpsvcs_log.log"); LPTSTR ServiceName = _T("Simp Tcp"); //LPTSTR DisplayName = _T("Simple TCP/IP Services");
@@ -69,19 +69,19 @@ VOID WINAPI ServiceMain(DWORD argc, LPTSTR argv[]) { - TCHAR LogFilePath[MAX_PATH]; + TCHAR LogFilePath[MAX_PATH + 17];
if(! GetSystemDirectory(LogFilePath, MAX_PATH)) return;
- _tcscat(LogFilePath, LogFileName); + _tcsncat(LogFilePath, LogFileName, 17);
- hLogFile = fopen(LogFilePath, _T("a+")); + hLogFile = _tfopen(LogFilePath, _T("a+")); if (hLogFile == NULL) { - TCHAR buf[50]; + TCHAR buf[300];
- _stprintf(buf, _T("Could not open log file: %s\n"), LogFilePath); + _sntprintf(buf, 300, _T("Could not open log file: %s\n"), LogFilePath); MessageBox(NULL, buf, NULL, MB_OK); return; } @@ -120,7 +120,7 @@ UpdateStatus (SERVICE_STOPPED, 0); LogEvent(_T("Service status set to SERVICE_STOPPED\n"), 0, FALSE); LogEvent(_T("Leaving ServiceMain\n"), 0, FALSE); - + fclose(hLogFile);
return; @@ -232,10 +232,10 @@ { CloseHandle(hThread[i]); } - + LogEvent(_T("Detaching Winsock2...\n"), 0, FALSE); WSACleanup(); - + return 0; }
@@ -247,7 +247,7 @@ { DWORD eMsgLen, ErrNum = GetLastError (); LPTSTR lpvSysMsg; - TCHAR MessageBuffer[512]; + TCHAR MessageBuffer[1024];
@@ -258,16 +258,16 @@ ErrNum, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpvSysMsg, 0, NULL);
- _stprintf(MessageBuffer, _T("%s %s ErrNum = %lu. ExitCode = %d."), + _sntprintf(MessageBuffer, 1024, _T("%s %s ErrNum = %lu. ExitCode = %d."), UserMessage, lpvSysMsg, ErrNum, ExitCode); HeapFree(GetProcessHeap (), 0, lpvSysMsg); } else { - _stprintf(MessageBuffer, _T("%s"), UserMessage); + _sntprintf(MessageBuffer, 1024, _T("%s"), UserMessage); }
- fputs (MessageBuffer, hLogFile); + _fputts(MessageBuffer, hLogFile);
if (ExitCode != 0) ExitProcess(ExitCode); _____
Modified: trunk/reactos/base/services/tcpsvcs/tcpsvcs.h --- trunk/reactos/base/services/tcpsvcs/tcpsvcs.h 2006-02-02 20:20:51 UTC (rev 72) +++ trunk/reactos/base/services/tcpsvcs/tcpsvcs.h 2006-02-03 17:36:44 UTC (rev 73) @@ -4,7 +4,7 @@
* FILE: /base/services/tcpsvcs/tcpsvcs.h * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com - * + * */
#include <stdio.h> @@ -12,9 +12,6 @@ #include <tchar.h> #include <time.h>
-#define UNICODE -#define _UNICODE - /* default port numbers */ #define ECHO_PORT 7 #define DISCARD_PORT 9 @@ -63,11 +60,11 @@ /* chargen functions */ DWORD WINAPI ChargenHandler(VOID* Sock_); BOOL GenerateChars(SOCKET Sock); -BOOL SendLine(SOCKET Sock, TCHAR* Line); +BOOL SendLine(SOCKET Sock, char* Line);
/* daytime functions */ DWORD WINAPI DaytimeHandler(VOID* Sock_); -BOOL SendTime(SOCKET Sock, TCHAR *time); +BOOL SendTime(SOCKET Sock, char *time);
/* echo functions */ DWORD WINAPI EchoHandler(VOID* Sock_); @@ -79,4 +76,4 @@
/* qotd functions */ DWORD WINAPI QotdHandler(VOID* Sock_); -BOOL SendQuote(SOCKET Sock, TCHAR* Quote); +BOOL SendQuote(SOCKET Sock, char* Quote);