Use snprintf() with size of the portstr buf

This commit is contained in:
Mukund Sivaraman 2009-11-17 01:44:21 +05:30
parent 238e3ffb34
commit 4b6a25ac06

View File

@ -167,7 +167,7 @@ int socket_blocking (int sock)
int listen_sock (uint16_t port, socklen_t * addrlen) int listen_sock (uint16_t port, socklen_t * addrlen)
{ {
struct addrinfo hints, *result, *rp; struct addrinfo hints, *result, *rp;
char portstr[32]; char portstr[6];
int listenfd; int listenfd;
const int on = 1; const int on = 1;
@ -178,7 +178,7 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
sprintf (portstr, "%6d", port); snprintf (portstr, sizeof (portstr), "%d", port);
if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) { if (getaddrinfo (config.ipAddr, portstr, &hints, &result) != 0) {
log_message (LOG_ERR, log_message (LOG_ERR,