From owner-svn-src-all@freebsd.org Sat Aug 19 09:38:45 2017 Return-Path: Delivered-To: svn-src-all@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 7F91EDDD8D2; Sat, 19 Aug 2017 09:38:45 +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 5B2336D69E; Sat, 19 Aug 2017 09:38:45 +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 v7J9cilP037678; Sat, 19 Aug 2017 09:38:44 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7J9chGd037675; Sat, 19 Aug 2017 09:38:43 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201708190938.v7J9chGd037675@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 19 Aug 2017 09:38:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r322692 - in stable/11/lib/libc: stdlib string tests/string X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/11/lib/libc: stdlib string tests/string X-SVN-Commit-Revision: 322692 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Aug 2017 09:38:45 -0000 Author: kib Date: Sat Aug 19 09:38:43 2017 New Revision: 322692 URL: https://svnweb.freebsd.org/changeset/base/322692 Log: MFC r322427: Improve standard compliance for memset_s() and abort_handler_s(). Modified: stable/11/lib/libc/stdlib/set_constraint_handler_s.c stable/11/lib/libc/string/memset_s.c stable/11/lib/libc/tests/string/memset_s_test.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/stdlib/set_constraint_handler_s.c ============================================================================== --- stable/11/lib/libc/stdlib/set_constraint_handler_s.c Sat Aug 19 01:49:09 2017 (r322691) +++ stable/11/lib/libc/stdlib/set_constraint_handler_s.c Sat Aug 19 09:38:43 2017 (r322692) @@ -33,6 +33,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #include "un-namespace.h" #include "libc_private.h" @@ -81,10 +83,14 @@ __throw_constraint_handler_s(const char * restrict msg } void -abort_handler_s(const char * restrict msg __unused, - void * restrict ptr __unused, errno_t error __unused) +abort_handler_s(const char * restrict msg, void * restrict ptr __unused, + errno_t error __unused) { + static const char ahs[] = "abort_handler_s : "; + (void) _write(STDERR_FILENO, ahs, sizeof(ahs) - 1); + (void) _write(STDERR_FILENO, msg, strlen(msg)); + (void) _write(STDERR_FILENO, "\n", 1); abort(); } Modified: stable/11/lib/libc/string/memset_s.c ============================================================================== --- stable/11/lib/libc/string/memset_s.c Sat Aug 19 01:49:09 2017 (r322691) +++ stable/11/lib/libc/string/memset_s.c Sat Aug 19 09:38:43 2017 (r322692) @@ -42,7 +42,7 @@ memset_s(void *s, rsize_t smax, int c, rsize_t n) volatile unsigned char *dst; ret = EINVAL; - lim = smax; + lim = n < smax ? n : smax; v = (unsigned char)c; dst = (unsigned char *)s; if (s == NULL) { @@ -53,11 +53,14 @@ memset_s(void *s, rsize_t smax, int c, rsize_t n) } else if (n > RSIZE_MAX) { __throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret); } else { - if (n < smax) - lim = n; while (lim > 0) dst[--lim] = v; - ret = 0; + if (n > smax) { + __throw_constraint_handler_s("memset_s : n > smax", + ret); + } else { + ret = 0; + } } return (ret); } Modified: stable/11/lib/libc/tests/string/memset_s_test.c ============================================================================== --- stable/11/lib/libc/tests/string/memset_s_test.c Sat Aug 19 01:49:09 2017 (r322691) +++ stable/11/lib/libc/tests/string/memset_s_test.c Sat Aug 19 09:38:43 2017 (r322692) @@ -109,13 +109,18 @@ ATF_TC_BODY(n_lt_smax, tc) assert(b[2] == 3); } -/* n > smax */ +/* n > smax, handler */ ATF_TC_WITHOUT_HEAD(n_gt_smax); ATF_TC_BODY(n_gt_smax, tc) { char b[3] = {1, 2, 3}; - assert(memset_s(&b[0], 1, 9, 3) == 0); + e = 0; + m = NULL; + set_constraint_handler_s(h); + assert(memset_s(&b[0], 1, 9, 3) != 0); + assert(e > 0); + assert(strcmp(m, "memset_s : n > smax") == 0); assert(b[0] == 9); assert(b[1] == 2); assert(b[2] == 3);