Commit 6f9eb5a1 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Lasse Karstensen

Harden vtcp_sa_to_ascii

Require that buffer arguments have greater than zero length to allow
for zero termination.

Make sure that NULL buffers are not touched.
parent 1a59d8e7
......@@ -61,6 +61,8 @@ vtcp_sa_to_ascii(const void *sa, socklen_t l, char *abuf, unsigned alen,
{
int i;
assert(abuf == NULL || alen > 0);
assert(pbuf == NULL || plen > 0);
i = getnameinfo(sa, l, abuf, alen, pbuf, plen,
NI_NUMERICHOST | NI_NUMERICSERV);
if (i) {
......@@ -69,12 +71,14 @@ vtcp_sa_to_ascii(const void *sa, socklen_t l, char *abuf, unsigned alen,
* for the gai_strerror in the bufffer :-(
*/
printf("getnameinfo = %d %s\n", i, gai_strerror(i));
(void)snprintf(abuf, alen, "Conversion");
(void)snprintf(pbuf, plen, "Failed");
if (abuf != NULL)
(void)snprintf(abuf, alen, "Conversion");
if (pbuf != NULL)
(void)snprintf(pbuf, plen, "Failed");
return;
}
/* XXX dirty hack for v4-to-v6 mapped addresses */
if (strncmp(abuf, "::ffff:", 7) == 0) {
if (abuf != NULL && strncmp(abuf, "::ffff:", 7) == 0) {
for (i = 0; abuf[i + 7]; ++i)
abuf[i] = abuf[i + 7];
abuf[i] = '\0';
......
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