From owner-svn-src-stable@freebsd.org Thu Feb 9 21:23:43 2017 Return-Path: Delivered-To: svn-src-stable@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 6CF3CCD88C8; Thu, 9 Feb 2017 21:23:43 +0000 (UTC) (envelope-from ngie@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 2F6EA15E3; Thu, 9 Feb 2017 21:23:43 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v19LNgae071870; Thu, 9 Feb 2017 21:23:42 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v19LNg0P071867; Thu, 9 Feb 2017 21:23:42 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201702092123.v19LNg0P071867@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Thu, 9 Feb 2017 21:23:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r313480 - in stable/10: contrib/netbsd-tests/lib/libc/string lib/libc/string X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Feb 2017 21:23:43 -0000 Author: ngie Date: Thu Feb 9 21:23:41 2017 New Revision: 313480 URL: https://svnweb.freebsd.org/changeset/base/313480 Log: MFC r283584: Relnotes: yes r283584 (by emaste): memmem(3): empty little string matches the beginning of the big string This function originated in glibc, and this matches their behaviour (and NetBSD, OpenBSD, and musl). An empty big string (arg "l") is handled by the existing l_len < s_len test. Modified: stable/10/contrib/netbsd-tests/lib/libc/string/t_memmem.c stable/10/lib/libc/string/memmem.3 stable/10/lib/libc/string/memmem.c Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/netbsd-tests/lib/libc/string/t_memmem.c ============================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/string/t_memmem.c Thu Feb 9 21:19:24 2017 (r313479) +++ stable/10/contrib/netbsd-tests/lib/libc/string/t_memmem.c Thu Feb 9 21:23:41 2017 (r313480) @@ -75,7 +75,7 @@ ATF_TC_HEAD(memmem_basic, tc) ATF_TC_BODY(memmem_basic, tc) { -#if defined(__darwin__) || defined(__FreeBSD__) +#if defined(__darwin__) expect(memmem(b2, lb2, p0, lp0) == NULL); expect(memmem(b0, lb0, p0, lp0) == NULL); #else Modified: stable/10/lib/libc/string/memmem.3 ============================================================================== --- stable/10/lib/libc/string/memmem.3 Thu Feb 9 21:19:24 2017 (r313479) +++ stable/10/lib/libc/string/memmem.3 Thu Feb 9 21:23:41 2017 (r313480) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 24, 2005 +.Dd May 26, 2015 .Dt MEMMEM 3 .Os .Sh NAME @@ -51,14 +51,12 @@ in the byte string .Fa big . .Sh RETURN VALUES If -.Fa big_len -is smaller than -.Fa little_len , -if .Fa little_len -is 0, if -.Fa big_len -is 0 or if +is zero +.Fa big +is returned (that is, an empty little is deemed to match at the beginning of +big); +if .Fa little occurs nowhere in .Fa big , @@ -84,3 +82,11 @@ function first appeared in .Sh BUGS This function was broken in Linux libc up to and including version 5.0.9 and in GNU libc prior to version 2.1. +Prior to +.Fx 11.0 +.Nm +returned +.Dv NULL +when +.Fa little_len +equals 0. Modified: stable/10/lib/libc/string/memmem.c ============================================================================== --- stable/10/lib/libc/string/memmem.c Thu Feb 9 21:19:24 2017 (r313479) +++ stable/10/lib/libc/string/memmem.c Thu Feb 9 21:23:41 2017 (r313480) @@ -42,9 +42,9 @@ memmem(const void *l, size_t l_len, cons const char *cl = (const char *)l; const char *cs = (const char *)s; - /* we need something to compare */ - if (l_len == 0 || s_len == 0) - return NULL; + /* empty "s" matches the beginning of "l" */ + if (s_len == 0) + return (void *)cl; /* "s" must be smaller or equal to "l" */ if (l_len < s_len)