From 8f0f742e611059bd3b312aa9986e94e4bfc4e63e Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Mon, 30 Mar 2015 21:13:22 +0000 Subject: HTTPServer: Minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@12566 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/HTTPServer/src/HttpUser.cpp | 4 ++-- plugins/HTTPServer/src/IndexHTML.cpp | 8 ++++---- plugins/HTTPServer/src/IndexXML.cpp | 18 +++++++++--------- plugins/HTTPServer/src/main.cpp | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/HTTPServer/src/HttpUser.cpp b/plugins/HTTPServer/src/HttpUser.cpp index ee196fbcb5..6acffb37ff 100644 --- a/plugins/HTTPServer/src/HttpUser.cpp +++ b/plugins/HTTPServer/src/HttpUser.cpp @@ -396,8 +396,8 @@ bool CLHttpUser::bProcessGetRequest(char * pszRequest, bool bIsGetCommand) { char* pszRealPath = pclCur->st.pszRealPath; if (pclCur->bIsDirectory()) { - strcpy(szRealPath, pclCur->st.pszRealPath); - strcpy(szSrvPath, pclCur->st.pszSrvPath); + strncpy(szRealPath, pclCur->st.pszRealPath, MAX_PATH); + strncpy(szSrvPath, pclCur->st.pszSrvPath, MAX_PATH); pszRealPath = szRealPath; pszSrvPath = szSrvPath; diff --git a/plugins/HTTPServer/src/IndexHTML.cpp b/plugins/HTTPServer/src/IndexHTML.cpp index f1f15fbc44..bf6b139529 100644 --- a/plugins/HTTPServer/src/IndexHTML.cpp +++ b/plugins/HTTPServer/src/IndexHTML.cpp @@ -62,8 +62,8 @@ bool LoadIndexHTMLTemplate() { char szDestBuf[10000]; char* pszDestBuf = szDestBuf; - strcpy(pszBuf, szPluginPath); - strcat(pszBuf, szIndexHTMLTemplateFile); + strncpy(pszBuf, szPluginPath, SIZEOF(szBuf)-1); + strncat(pszBuf, szIndexHTMLTemplateFile, SIZEOF(szBuf)-1); HANDLE hFile = CreateFile(pszBuf, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); @@ -283,8 +283,8 @@ bool bCreateIndexHTML(const char * pszRealPath, const char * pszIndexPath, // check if directory exists char szMask[MAX_PATH]; - strcpy(szMask, pszRealPath); - strcat(szMask, "*"); + strncpy(szMask, pszRealPath, MAX_PATH- 1); + strncat(szMask, "*", MAX_PATH- 1); WIN32_FIND_DATAA fdFindFileData; HANDLE hFind = FindFirstFile(szMask, &fdFindFileData); diff --git a/plugins/HTTPServer/src/IndexXML.cpp b/plugins/HTTPServer/src/IndexXML.cpp index 942e572433..443f410b1f 100644 --- a/plugins/HTTPServer/src/IndexXML.cpp +++ b/plugins/HTTPServer/src/IndexXML.cpp @@ -32,7 +32,7 @@ static void ReplaceSign(char* pszSrc, int MaxLength, const char pszReplace, char* pszSign = strchr(pszSrc, pszReplace); if (pszSign) { - strcpy(szBuffer, pszSrc); + strncpy(szBuffer, pszSrc, SIZEOF(szBuffer)-1); do { strcpy(szBuffer + (pszSign - pszSrc), pszNew); @@ -64,8 +64,8 @@ static void ReplaceSign(char* pszSrc, int MaxLength, const char pszReplace, bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const char * pszSrvPath, DWORD dwRemoteIP) { char szMask[MAX_PATH+1]; - strcpy(szMask, pszRealPath); - strcat(szMask, "*"); + strncpy(szMask, pszRealPath, MAX_PATH); + strncat(szMask, "*", MAX_PATH); WIN32_FIND_DATAA fdFindFileData; HANDLE hFind = FindFirstFile(szMask, &fdFindFileData); @@ -89,31 +89,31 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, DWORD dwBytesWritten = 0; // Generate Dirname - strcpy(szBuffer, pszSrvPath); + strncpy(szBuffer, pszSrvPath, BUFFER_SIZE); char* pszTemp = strrchr(szBuffer, '/'); if (pszTemp) *pszTemp = '\0'; pszTemp = strrchr(szBuffer, '/'); if (pszTemp) - strcpy(szFileName, pszTemp + 1); + strncpy(szFileName, pszTemp + 1, MAX_PATH); // Write Header WriteFile(hFile, szXmlHeader1, sizeof(szXmlHeader1) - 1, &dwBytesWritten, NULL); // check if a index.xsl exists in the same directory otherwise use the global - strcpy(szMask, pszRealPath); - strcat(szMask, "index.xsl"); + strncpy(szMask, pszRealPath, MAX_PATH); + strncat(szMask, "index.xsl", MAX_PATH); HANDLE hFileExists = CreateFile(szMask, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFileExists == INVALID_HANDLE_VALUE) { - strcpy(szBuffer, "/index.xsl"); + strncpy(szBuffer, "/index.xsl", BUFFER_SIZE); } else { CloseHandle(hFileExists); - strcpy(szBuffer, "index.xsl"); + strncpy(szBuffer, "index.xsl", BUFFER_SIZE); } WriteFile(hFile, szBuffer, (DWORD)strlen(szBuffer), &dwBytesWritten, NULL); diff --git a/plugins/HTTPServer/src/main.cpp b/plugins/HTTPServer/src/main.cpp index 89b61986c6..d2ababd31b 100644 --- a/plugins/HTTPServer/src/main.cpp +++ b/plugins/HTTPServer/src/main.cpp @@ -728,11 +728,11 @@ int MainInit(WPARAM /*wparam*/, LPARAM /*lparam*/) { share.pszRealPath = szRealPath; share.dwMaxRealPath = sizeof(szRealPath); - strcpy(share.pszRealPath, p[0]); + strncpy(share.pszRealPath, p[0], SIZEOF(share.pszRealPath) - 1); share.pszSrvPath = szSrvPath; share.dwMaxSrvPath = sizeof(szSrvPath); - strcpy(share.pszSrvPath, p[1]); + strncpy(share.pszSrvPath, p[1], SIZEOF(share.pszSrvPath) - 1); if (CallService(MS_HTTP_ADD_CHANGE_REMOVE, 0, (LPARAM)&share)) break; -- cgit v1.2.3