From 4c7fa1aabf718c54e671a63ce862063fd9d1103a Mon Sep 17 00:00:00 2001 From: Will Elwood Date: Wed, 16 Nov 2016 15:43:29 +0000 Subject: [PATCH 1/2] Fix version.sh for ancient git I'm not sure when the `format` argument was added to `git log`, but it seems to be an alias for `pretty` (ie both exist in current versions of git). I noticed this was failing on my ancient system that's stuck with git 1.5, this makes it work. Also, `ignore-submodules` is not understood by ancient `git status` - I believe the expected output would be achieved by simply removing this argument, but it's not important since it fails gracefully enough and fixing it so newer git doesn't fail seems more complicated. --- version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.sh b/version.sh index 9b8daeba..339bfe5a 100755 --- a/version.sh +++ b/version.sh @@ -16,7 +16,7 @@ else # Figure out the information we need LATEST_TAG=`${GIT} describe --abbrev=0 HEAD` - COMMITS_SINCE=`${GIT} log --format=oneline ${LATEST_TAG}..HEAD | wc -l` + COMMITS_SINCE=`${GIT} log --pretty=oneline ${LATEST_TAG}..HEAD | wc -l` # Explicitly make it a number: on openbsd wc -l returns " 42" instead of "42" let COMMITS_SINCE=COMMITS_SINCE SHORT_ID=`${GIT} rev-parse --short HEAD` From 6366430870858fb6ef44be41236f2685177f6799 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 20 Nov 2016 17:52:26 +0000 Subject: [PATCH 2/2] Fix deletion of users which are connecting. Close #1342 --- include/znc/Socket.h | 1 + src/Socket.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/znc/Socket.h b/include/znc/Socket.h index 9ad3cdb7..51abf162 100644 --- a/include/znc/Socket.h +++ b/include/znc/Socket.h @@ -131,6 +131,7 @@ public: void Connect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout = 60, bool bSSL = false, const CString& sBindHost = "", CZNCSock *pcSock = NULL); unsigned int GetAnonConnectionCount(const CString &sIP) const; + void DelSockByAddr(Csock* pcSock) override; private: void FinishConnect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock *pcSock); diff --git a/src/Socket.cpp b/src/Socket.cpp index 6870e492..7c7fba50 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -349,12 +349,16 @@ CSockManager::CSockManager() { CSockManager::~CSockManager() { } +// It's here to not break ABI of 1.6; in 1.7 this should be a data member of CSockManager. +static std::map g_InFlightDnsSockets; + void CSockManager::Connect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock *pcSock) { + g_InFlightDnsSockets[pcSock] = false; if (pcSock) { pcSock->SetHostToVerifySSL(sHostname); } #ifdef HAVE_THREADED_DNS - DEBUG("TDNS: initiating resolving of [" << sHostname << "] and bindhost [" << sBindHost << "]"); + DEBUG("TDNS: initiating resolving of [" << sHostname << "] and bindhost [" << sBindHost << "] for [" << sSockName << "]"); TDNSTask* task = new TDNSTask; task->sHostname = sHostname; task->iPort = iPort; @@ -380,6 +384,18 @@ void CSockManager::Connect(const CString& sHostname, u_short iPort, const CStrin } void CSockManager::FinishConnect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock *pcSock) { + auto it = g_InFlightDnsSockets.find(pcSock); + if (it != g_InFlightDnsSockets.end()) { + bool bSocketDeletedAlready = it->second; + g_InFlightDnsSockets.erase(it); + if (bSocketDeletedAlready) { + DEBUG("TDNS: Socket [" << sSockName << "] is deleted already, not proceeding with connection"); + return; + } + } else { + // impossible + } + CSConnection C(sHostname, iPort, iTimeout); C.SetSockName(sSockName); @@ -396,6 +412,15 @@ void CSockManager::FinishConnect(const CString& sHostname, u_short iPort, const TSocketManager::Connect(C, pcSock); } +void CSockManager::DelSockByAddr(Csock* pcSock) { + auto it = g_InFlightDnsSockets.find(pcSock); + if (it != g_InFlightDnsSockets.end()) { + // Then socket is resolving its DNS. When that finishes, let it silently die without crash. + it->second = true; + } + TSocketManager::DelSockByAddr(pcSock); +} + /////////////////// CSocket /////////////////// CSocket::CSocket(CModule* pModule) : CZNCSock() {