sa/sa_ntop: check inet_ntop() return value
On success, inet_ntop() returns a non-null pointer to dst.  NULL is
returned if there was an error, with errno set to indicate the error.
@@ -400,18 +400,20 @@ void sa_in6(const struct sa *sa, uint8_t *addr)
*/
int sa_ntop(const struct sa *sa, char *buf, int size)
{
+ const char *ret;
+
if (!sa || !buf || !size)
return EINVAL;
switch (sa->u.sa.sa_family) {
case AF_INET:
- inet_ntop(AF_INET, &sa->u.in.sin_addr, buf, size);
+ ret = inet_ntop(AF_INET, &sa->u.in.sin_addr, buf, size);
break;
#ifdef HAVE_INET6
case AF_INET6:
- inet_ntop(AF_INET6, &sa->u.in6.sin6_addr, buf, size);
+ ret = inet_ntop(AF_INET6, &sa->u.in6.sin6_addr, buf, size);
break;
#endif
@@ -419,6 +421,9 @@ int sa_ntop(const struct sa *sa, char *buf, int size)
return EAFNOSUPPORT;
}
+ if (!ret)
+ return errno;
+
return 0;
}
