Commit f50a480b authored by knowledge4igor's avatar knowledge4igor

Fix memory defect in http header

parent a95c97af
...@@ -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); memcpy(buff6, host_.c_str(), host_.size());
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); memcpy(buff, host_.c_str(), host_.size());
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