Don’t allow resolving of std::string
:s with embedded NUL
characters.
Avoid using C-style NUL
-terminated strings as arguments in the netbase
interface
Add tests.
The only place in where C-style NUL
-terminated strings are actually needed is here:
0+ if (!ValidAsCString(name)) {
1+ return false;
2+ }
3...
4- int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
5+ int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes);
6 if (nErr)
7 return false;
Interface changes:
0-bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
1+bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
2
3-bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
4+bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
5
6-bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
7+bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
8
9-bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
10+bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
11
12-bool LookupSubNet(const char *pszName, CSubNet& subnet);
13+bool LookupSubNet(const std::string& strSubnet, CSubNet& subnet);
14
15-CService LookupNumeric(const char *pszName, int portDefault = 0);
16+CService LookupNumeric(const std::string& name, int portDefault = 0);
17
18-bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
19+bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool& outProxyConnectionFailed);
It should be noted that the ConnectThroughProxy
change (from bool *outProxyConnectionFailed
to bool& outProxyConnectionFailed
) has nothing to do with NUL
handling but I thought it was worth doing when touching this file :)