From owner-svn-src-head@freebsd.org Thu Sep 14 19:18:25 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C36E4E05C31; Thu, 14 Sep 2017 19:18:25 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 92C8B654DF; Thu, 14 Sep 2017 19:18:25 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8EJIONG065196; Thu, 14 Sep 2017 19:18:24 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8EJIOLu065194; Thu, 14 Sep 2017 19:18:24 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709141918.v8EJIOLu065194@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 14 Sep 2017 19:18:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323597 - head/lib/libc/net X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/lib/libc/net X-SVN-Commit-Revision: 323597 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2017 19:18:25 -0000 Author: kib Date: Thu Sep 14 19:18:24 2017 New Revision: 323597 URL: https://svnweb.freebsd.org/changeset/base/323597 Log: Silently handle freeaddrinfo(NULL) for compatibility with code which works on other OSes. Also avoid unnecessary NULL check, free(NULL) is valid. Reviewed by: bjk (man page), hrs, hselasky, ume Sponsored by: Mellanox Technologies MFC after: 1 week Differential revision: https://reviews.freebsd.org/D12354 Modified: head/lib/libc/net/getaddrinfo.3 head/lib/libc/net/getaddrinfo.c Modified: head/lib/libc/net/getaddrinfo.3 ============================================================================== --- head/lib/libc/net/getaddrinfo.3 Thu Sep 14 18:50:40 2017 (r323596) +++ head/lib/libc/net/getaddrinfo.3 Thu Sep 14 19:18:24 2017 (r323597) @@ -18,7 +18,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 21, 2015 +.Dd September 13, 2017 .Dt GETADDRINFO 3 .Os .Sh NAME @@ -351,6 +351,17 @@ pointer should be a .Li addrinfo structure created by a call to .Fn getaddrinfo . +.Sh IMPLEMENTATION NOTES +The behavior of +.Li freeadrinfo(NULL) +is left unspecified by both +.St -susv4 +and +.Dv "RFC 3493" . +The current implementation ignores a +.Dv NULL +argument for compatibility with programs that rely on the implementation +details of other operating systems. .Sh RETURN VALUES .Fn getaddrinfo returns zero on success or one of the error codes listed in Modified: head/lib/libc/net/getaddrinfo.c ============================================================================== --- head/lib/libc/net/getaddrinfo.c Thu Sep 14 18:50:40 2017 (r323596) +++ head/lib/libc/net/getaddrinfo.c Thu Sep 14 19:18:24 2017 (r323597) @@ -35,7 +35,7 @@ * in the source code. This is because RFC2553 is silent about which error * code must be returned for which situation. * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is - * invalid. current code - SEGV on freeaddrinfo(NULL) + * invalid. Current code accepts NULL to be compatible with other OSes. * * Note: * - The code filters out AFs that are not supported by the kernel, @@ -359,14 +359,13 @@ freeaddrinfo(struct addrinfo *ai) { struct addrinfo *next; - do { + while (ai != NULL) { next = ai->ai_next; - if (ai->ai_canonname) - free(ai->ai_canonname); + free(ai->ai_canonname); /* no need to free(ai->ai_addr) */ free(ai); ai = next; - } while (ai); + } } static int