Unverified Commit f95ee72f authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #427 from knowledge4igor/fix_memory_defect_in_http_header

Fix memory defect in http header
parents 0d28b768 6d604fe5
...@@ -346,11 +346,11 @@ Host::parse(const std::string& data) { ...@@ -346,11 +346,11 @@ Host::parse(const std::string& data) {
unsigned long s_pos = data.find('['); unsigned long s_pos = data.find('[');
if (pos != std::string::npos && s_pos != std::string::npos) { if (pos != std::string::npos && s_pos != std::string::npos) {
//IPv6 address //IPv6 address
host_ = data.substr(s_pos, pos+1); host_ = data.substr(s_pos, pos + 1);
try { try {
in6_addr addr6; in6_addr addr6;
char buff6[INET6_ADDRSTRLEN+1]; char buff6[INET6_ADDRSTRLEN + 1] = {0, };
memcpy(buff6, host_.c_str(), INET6_ADDRSTRLEN); std::copy(&host_[0], &host_[0] + host_.size(), buff6);
inet_pton(AF_INET6, buff6, &(addr6.s6_addr16)); inet_pton(AF_INET6, buff6, &(addr6.s6_addr16));
} catch (std::runtime_error) { } catch (std::runtime_error) {
throw std::invalid_argument("Invalid IPv6 address"); throw std::invalid_argument("Invalid IPv6 address");
...@@ -369,8 +369,8 @@ Host::parse(const std::string& data) { ...@@ -369,8 +369,8 @@ Host::parse(const std::string& data) {
} }
try { try {
in_addr addr; in_addr addr;
char buff[INET_ADDRSTRLEN+1]; char buff[INET_ADDRSTRLEN + 1] = {0, };
memcpy(buff, host_.c_str(), INET_ADDRSTRLEN); std::copy(&host_[0], &host_[0] + host_.size(), buff);
inet_pton(AF_INET, buff, &(addr)); inet_pton(AF_INET, buff, &(addr));
} catch (std::runtime_error) { } catch (std::runtime_error) {
throw std::invalid_argument("Invalid IPv4 address"); throw std::invalid_argument("Invalid IPv4 address");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment