Assert that various buffers we are large enough.
MFC after: 1 month
This commit is contained in:
parent
524840d8d0
commit
2c5dadc9cf
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=210876
@ -156,7 +156,8 @@ tcp4_addr(const char *addr, struct sockaddr_in *sinp)
|
|||||||
size = (size_t)(pp - addr + 1);
|
size = (size_t)(pp - addr + 1);
|
||||||
if (size > sizeof(iporhost))
|
if (size > sizeof(iporhost))
|
||||||
return (ENAMETOOLONG);
|
return (ENAMETOOLONG);
|
||||||
strlcpy(iporhost, addr, size);
|
if (strlcpy(iporhost, addr, size) >= size)
|
||||||
|
return (ENAMETOOLONG);
|
||||||
}
|
}
|
||||||
/* Convert string (IP address or host name) to in_addr_t. */
|
/* Convert string (IP address or host name) to in_addr_t. */
|
||||||
ip = str2ip(iporhost);
|
ip = str2ip(iporhost);
|
||||||
@ -420,8 +421,9 @@ sin2str(struct sockaddr_in *sinp, char *addr, size_t size)
|
|||||||
|
|
||||||
ip = ntohl(sinp->sin_addr.s_addr);
|
ip = ntohl(sinp->sin_addr.s_addr);
|
||||||
port = ntohs(sinp->sin_port);
|
port = ntohs(sinp->sin_port);
|
||||||
snprintf(addr, size, "tcp4://%u.%u.%u.%u:%u", ((ip >> 24) & 0xff),
|
PJDLOG_VERIFY(snprintf(addr, size, "tcp4://%u.%u.%u.%u:%u",
|
||||||
((ip >> 16) & 0xff), ((ip >> 8) & 0xff), (ip & 0xff), port);
|
((ip >> 24) & 0xff), ((ip >> 16) & 0xff), ((ip >> 8) & 0xff),
|
||||||
|
(ip & 0xff), port) < (ssize_t)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@ -459,7 +461,7 @@ tcp4_local_address(const void *ctx, char *addr, size_t size)
|
|||||||
|
|
||||||
sinlen = sizeof(sin);
|
sinlen = sizeof(sin);
|
||||||
if (getsockname(tctx->tc_fd, (struct sockaddr *)&sin, &sinlen) < 0) {
|
if (getsockname(tctx->tc_fd, (struct sockaddr *)&sin, &sinlen) < 0) {
|
||||||
strlcpy(addr, "N/A", size);
|
PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sin2str(&sin, addr, size);
|
sin2str(&sin, addr, size);
|
||||||
@ -477,7 +479,7 @@ tcp4_remote_address(const void *ctx, char *addr, size_t size)
|
|||||||
|
|
||||||
sinlen = sizeof(sin);
|
sinlen = sizeof(sin);
|
||||||
if (getpeername(tctx->tc_fd, (struct sockaddr *)&sin, &sinlen) < 0) {
|
if (getpeername(tctx->tc_fd, (struct sockaddr *)&sin, &sinlen) < 0) {
|
||||||
strlcpy(addr, "N/A", size);
|
PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sin2str(&sin, addr, size);
|
sin2str(&sin, addr, size);
|
||||||
|
@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "hast.h"
|
#include "hast.h"
|
||||||
|
#include "pjdlog.h"
|
||||||
#include "proto_impl.h"
|
#include "proto_impl.h"
|
||||||
|
|
||||||
#define UDS_CTX_MAGIC 0xd541c
|
#define UDS_CTX_MAGIC 0xd541c
|
||||||
@ -257,15 +258,15 @@ uds_local_address(const void *ctx, char *addr, size_t size)
|
|||||||
|
|
||||||
sunlen = sizeof(sun);
|
sunlen = sizeof(sun);
|
||||||
if (getsockname(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) {
|
if (getsockname(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) {
|
||||||
strlcpy(addr, "N/A", size);
|
PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(sun.sun_family == AF_UNIX);
|
assert(sun.sun_family == AF_UNIX);
|
||||||
if (sun.sun_path[0] == '\0') {
|
if (sun.sun_path[0] == '\0') {
|
||||||
strlcpy(addr, "N/A", size);
|
PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snprintf(addr, size, "uds://%s", sun.sun_path);
|
PJDLOG_VERIFY(snprintf(addr, size, "uds://%s", sun.sun_path) < (ssize_t)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -281,12 +282,12 @@ uds_remote_address(const void *ctx, char *addr, size_t size)
|
|||||||
|
|
||||||
sunlen = sizeof(sun);
|
sunlen = sizeof(sun);
|
||||||
if (getpeername(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) {
|
if (getpeername(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) {
|
||||||
strlcpy(addr, "N/A", size);
|
PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(sun.sun_family == AF_UNIX);
|
assert(sun.sun_family == AF_UNIX);
|
||||||
if (sun.sun_path[0] == '\0') {
|
if (sun.sun_path[0] == '\0') {
|
||||||
strlcpy(addr, "N/A", size);
|
PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snprintf(addr, size, "uds://%s", sun.sun_path);
|
snprintf(addr, size, "uds://%s", sun.sun_path);
|
||||||
|
Loading…
Reference in New Issue
Block a user