Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Sep 2014 09:03:13 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r271187 - head/usr.sbin/ctld
Message-ID:  <201409060903.s8693DFV075543@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Sat Sep  6 09:03:13 2014
New Revision: 271187
URL: http://svnweb.freebsd.org/changeset/base/271187

Log:
  Avoid ctld(8) crash on getaddrinfo(3) failure.
  
  MFC after:	2 weeks
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/usr.sbin/ctld/ctld.c

Modified: head/usr.sbin/ctld/ctld.c
==============================================================================
--- head/usr.sbin/ctld/ctld.c	Sat Sep  6 08:48:57 2014	(r271186)
+++ head/usr.sbin/ctld/ctld.c	Sat Sep  6 09:03:13 2014	(r271187)
@@ -561,8 +561,10 @@ portal_new(struct portal_group *pg)
 static void
 portal_delete(struct portal *portal)
 {
+
 	TAILQ_REMOVE(&portal->p_portal_group->pg_portals, portal, p_next);
-	freeaddrinfo(portal->p_ai);
+	if (portal->p_ai != NULL)
+		freeaddrinfo(portal->p_ai);
 	free(portal->p_listen);
 	free(portal);
 }
@@ -633,8 +635,7 @@ portal_group_add_listen(struct portal_gr
 	arg = portal->p_listen;
 	if (arg[0] == '\0') {
 		log_warnx("empty listen address");
-		free(portal->p_listen);
-		free(portal);
+		portal_delete(portal);
 		return (1);
 	}
 	if (arg[0] == '[') {
@@ -646,8 +647,7 @@ portal_group_add_listen(struct portal_gr
 		if (arg == NULL) {
 			log_warnx("invalid listen address %s",
 			    portal->p_listen);
-			free(portal->p_listen);
-			free(portal);
+			portal_delete(portal);
 			return (1);
 		}
 		if (arg[0] == '\0') {
@@ -657,8 +657,7 @@ portal_group_add_listen(struct portal_gr
 		} else {
 			log_warnx("invalid listen address %s",
 			    portal->p_listen);
-			free(portal->p_listen);
-			free(portal);
+			portal_delete(portal);
 			return (1);
 		}
 	} else {
@@ -691,8 +690,7 @@ portal_group_add_listen(struct portal_gr
 	if (error != 0) {
 		log_warnx("getaddrinfo for %s failed: %s",
 		    portal->p_listen, gai_strerror(error));
-		free(portal->p_listen);
-		free(portal);
+		portal_delete(portal);
 		return (1);
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409060903.s8693DFV075543>