From 4a6acac1becf0af0be0deb9fc17d4cdcf8595071 Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Tue, 5 Jan 2010 11:34:44 +0000 Subject: Tighten SU_ADDRSTRLEN and sockunion2str() in lib/sockunion.c/.h Added confirms and assert for SU_ADDRSTRLEN in sockunion.h and in sockunion2str(). --- lib/sockunion.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/sockunion.c') diff --git a/lib/sockunion.c b/lib/sockunion.c index 054b17e6..d1fdb189 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -164,9 +164,16 @@ str2sockunion (const char *str, union sockunion *su) return -1; } +/*------------------------------------------------------------------------------ + * Construct string for sockunion IP address. + * + * Requires buffer of at least SU_ADDRSTRLEN characters. + */ const char * sockunion2str (union sockunion *su, char *buf, size_t len) { + assert(len >= SU_ADDRSTRLEN) ; + if (su->sa.sa_family == AF_INET) return inet_ntop (AF_INET, &su->sin.sin_addr, buf, len); #ifdef HAVE_IPV6 -- cgit v1.2.3