diff --git a/FileUtils.cpp b/FileUtils.cpp index 790a7a11..d744a82d 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -362,12 +362,22 @@ int CExecSock::popen2(int & iReadFD, int & iWriteFD, const CString & sCommand) { iReadFD = -1; iWriteFD = -1; - pipe(rpipes); - pipe(wpipes); + if (pipe(rpipes) < 0) + return -1; + + if (pipe(wpipes) < 0) { + close(rpipes[0]); + close(rpipes[1]); + return -1; + } int iPid = fork(); if (iPid == -1) { + close(rpipes[0]); + close(rpipes[1]); + close(wpipes[0]); + close(wpipes[1]); return -1; } @@ -379,14 +389,14 @@ int CExecSock::popen2(int & iReadFD, int & iWriteFD, const CString & sCommand) { dup2(rpipes[1], 2); close(wpipes[0]); close(rpipes[1]); - char * const pArgv[] = + const char * pArgv[] = { "sh", "-c", - (char *)sCommand.c_str(), + sCommand.c_str(), NULL }; - execvp( "sh", pArgv ); + execvp("sh", (char * const *) pArgv); exit(0); } diff --git a/Template.cpp b/Template.cpp index 1a838c84..3ff49821 100644 --- a/Template.cpp +++ b/Template.cpp @@ -450,8 +450,8 @@ CString CTemplate::GetValue(const CString& sArgs) { sRet = (it != end()) ? it->second : ""; } - while (sRest.Replace(" =", "=", "\"", "\"")); - while (sRest.Replace("= ", "=", "\"", "\"")); + while (sRest.Replace(" =", "=", "\"", "\"")) ; + while (sRest.Replace("= ", "=", "\"", "\"")) ; VCString vArgs; MCString msArgs; diff --git a/main.cpp b/main.cpp index 3848cbe3..36caa98f 100644 --- a/main.cpp +++ b/main.cpp @@ -120,7 +120,7 @@ int main(int argc, char** argv, char** envp) { CZNC& ZNC = CZNC::Get(); ZNC.InitDirs("", sDataDir); if (ZNC.WriteNewConfig(sConfig)) { - char* args[5]; + char const* args[5]; if (argc > 2) { args[0] = argv[0]; @@ -147,8 +147,8 @@ int main(int argc, char** argv, char** envp) { return 1; } - chdir(ZNC.GetCurPath().c_str()); - if (execve(*argv, args, envp) == -1) { + if ((chdir(ZNC.GetCurPath().c_str()) == -1) + || (execve(*argv, (char *const*)args, envp) == -1)) { CUtils::PrintError("Unable to launch znc [" + CString(strerror(errno)) + "]"); return 1; } diff --git a/modules/watch.cpp b/modules/watch.cpp index 1aabd5ae..7ba1e7b4 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -319,7 +319,8 @@ private: } list::iterator it = m_lsWatchers.begin(); - for (unsigned int a = 0; a < uIdx; a++, it++); + for (unsigned int a = 0; a < uIdx; a++) + it++; (*it).SetDisabled(bDisabled); PutModule("Id " + CString(uIdx +1) + ((bDisabled) ? " Disabled" : " Enabled")); @@ -396,7 +397,8 @@ private: } list::iterator it = m_lsWatchers.begin(); - for (unsigned int a = 0; a < uIdx; a++, it++); + for (unsigned int a = 0; a < uIdx; a++) + it++; (*it).SetSources(sSources); PutModule("Sources set for Id " + CString(uIdx +1) + "."); @@ -410,7 +412,8 @@ private: } list::iterator it = m_lsWatchers.begin(); - for (unsigned int a = 0; a < uIdx; a++, it++); + for (unsigned int a = 0; a < uIdx; a++) + it++; m_lsWatchers.erase(it); PutModule("Id " + CString(uIdx +1) + " Removed."); diff --git a/znc.cpp b/znc.cpp index 248f0a31..6e3a190c 100644 --- a/znc.cpp +++ b/znc.cpp @@ -280,7 +280,7 @@ bool CZNC::WritePemFile( bool bEncPem ) { return false; } - while (!CUtils::GetInput("hostname of your shell", sHost, sHost, "including the '.com' portion")); + while (!CUtils::GetInput("hostname of your shell", sHost, sHost, "including the '.com' portion")) ; CUtils::PrintAction("Writing Pem file [" + sPemFile + "]"); FILE *f = fopen(sPemFile.c_str(), "w"); @@ -330,7 +330,10 @@ bool CZNC::IsHostAllowed(const CString& sHostMask) { void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) { char buf[PATH_MAX]; - getcwd(buf, PATH_MAX); + if (getcwd(buf, PATH_MAX) == NULL) { + CUtils::PrintError("getcwd() failed, can't read my current dir"); + exit(-1); + } // If the bin was not ran from the current directory, we need to add that dir onto our cwd CString::size_type uPos = sArgvPath.rfind('/'); @@ -480,7 +483,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { // Listen unsigned int uPort = 0; - while(!CUtils::GetNumInput("What port would you like ZNC to listen on?", uPort, 1, 65535)); + while(!CUtils::GetNumInput("What port would you like ZNC to listen on?", uPort, 1, 65535)) ; CString sSSL; #ifdef HAVE_LIBSSL @@ -653,8 +656,8 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { bool bSSL = false; unsigned int uPort = 0; - while(!CUtils::GetInput("IRC server", sHost, "", "host only") || !CServer::IsValidHostName(sHost)); - while(!CUtils::GetNumInput("[" + sHost + "] Port", uPort, 1, 65535, 6667)); + while(!CUtils::GetInput("IRC server", sHost, "", "host only") || !CServer::IsValidHostName(sHost)) ; + while(!CUtils::GetNumInput("[" + sHost + "] Port", uPort, 1, 65535, 6667)) ; CUtils::GetInput("[" + sHost + "] Password (probably empty)", sPass); #ifdef HAVE_LIBSSL @@ -674,7 +677,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) { bool bDefault = true; while (CUtils::GetBoolInput("Would you like to add " + sArg + " channel" + sPost, bDefault)) { - while (!CUtils::GetInput("Channel name", sAnswer)); + while (!CUtils::GetInput("Channel name", sAnswer)) ; vsLines.push_back("\t"); vsLines.push_back("\t"); sArg = "another";