Fixed #132: invalid pointer to temporary buffer.

This commit is contained in:
Vincent Richard 2016-03-03 20:16:21 +01:00
parent 194a797055
commit 7d2ef7311e

View File

@ -44,6 +44,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include "vmime/utility/stringUtils.hpp" #include "vmime/utility/stringUtils.hpp"
@ -363,9 +364,8 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
void posixSocket::resolve(struct ::addrinfo** addrInfo, const vmime::string& address, const vmime::port_t port) void posixSocket::resolve(struct ::addrinfo** addrInfo, const vmime::string& address, const vmime::port_t port)
{ {
std::ostringstream portStr; char portStr[16];
portStr.imbue(std::locale::classic()); snprintf(portStr, sizeof(portStr), "%u", static_cast <unsigned int>(port));
portStr << port;
struct ::addrinfo hints; struct ::addrinfo hints;
@ -384,7 +384,7 @@ void posixSocket::resolve(struct ::addrinfo** addrInfo, const vmime::string& add
memset(&gaiRequest, 0, sizeof(gaiRequest)); memset(&gaiRequest, 0, sizeof(gaiRequest));
gaiRequest.ar_name = address.c_str(); gaiRequest.ar_name = address.c_str();
gaiRequest.ar_service = portStr.str().c_str(); gaiRequest.ar_service = portStr;
gaiRequest.ar_request = &hints; gaiRequest.ar_request = &hints;
struct ::gaicb* gaiRequests = &gaiRequest; struct ::gaicb* gaiRequests = &gaiRequest;