Commit Graph

176 Commits

Author SHA1 Message Date
Yuri Pankov
63cbe8d1d9 regexec: fix processing multibyte strings.
Matcher function incorrectly assumed that moffset that we get from
findmust is in bytes. Fix this by introducing a stepback function,
taking short path if MB_CUR_MAX is 1, and going back byte-by-byte,
checking if we have a legal character sequence otherwise.

PR:		153502
Reviewed by:	pfg, kevans
Approved by:	kib (mentor, implicit)
Differential revision:	https://reviews.freebsd.org/D18297
2018-11-23 15:49:18 +00:00
Yuri Pankov
281c29899f Connect libc/tests/time to the build, adding test cases for strptime()
issues fixed recently, and disabling the failing ones (mostly due to TZ
parsing differences with NetBSD).

Reviewed by:	ngie
Approved by:	kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D17546
2018-10-30 02:37:23 +00:00
Bryan Drewery
f272627fcd Rework check for libclang_rt to see if the needed library exists.
Currently libclang_rt is not provided for cross-building and as such
is not connected to cross-tools.  For building clang once in universe
it is likely that libclang_rt won't exist for the universe toolchain
but even if it did it would not support anything but the native arch.
So explicitly check for support before enabling h_raw.

MFC after:	1 week
Reviewed by:	dim
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D16012
2018-06-27 16:56:46 +00:00
Mark Johnston
ea16e3e1e7 Don't build brk_test on platforms that don't support brk().
X-MFC with:	r334626
2018-06-05 13:06:06 +00:00
Mark Johnston
9f9c9b22ec Reimplement brk() and sbrk() to avoid the use of _end.
Previously, libc.so would initialize its notion of the break address
using _end, a special symbol emitted by the static linker following
the bss section.  Compatibility issues between lld and ld.bfd could
cause the wrong definition of _end (libc.so's definition rather than
that of the executable) to be used, breaking the brk()/sbrk()
interface.

Avoid this problem and future interoperability issues by simply not
relying on _end.  Instead, modify the break() system call to return
the kernel's view of the current break address, and have libc
initialize its state using an extra syscall upon the first use of the
interface.  As a side effect, this appears to fix brk()/sbrk() usage
in executables run with rtld direct exec, since the kernel and libc.so
no longer maintain separate views of the process' break address.

PR:		228574
Reviewed by:	kib (previous version)
MFC after:	2 months
Differential Revision:	https://reviews.freebsd.org/D15663
2018-06-04 19:35:15 +00:00
Cy Schubert
c76af09019 Conform to Berne Convention.
MFC after:	3 days
2018-05-22 06:22:58 +00:00
Eric van Gyzen
488ab515d6 Remove 'All rights reserved' from my files
See r333391 for the rationale.

Approved by:	emaste (for the Foundation copyright)
Sponsored by:	Dell EMC
2018-05-09 20:12:59 +00:00
Cy Schubert
a77546fbb3 Add new gets_s(3) stdio function.
This implements the gets_s(3) function as documented at
http://en.cppreference.com/w/c/io/gets. It facilitates the
optional removal of gets(3).

Reviewed by:	ed
MFC after:	2 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D12785
2018-04-03 18:52:38 +00:00
Conrad Meyer
08a7e74c7c getentropy(3): Fallback to kern.arandom sysctl on older kernels
On older kernels, when userspace program disables SIGSYS, catch ENOSYS and
emulate getrandom(2) syscall with the kern.arandom sysctl (via existing
arc4_sysctl wrapper).

Special care is taken to faithfully emulate EFAULT on NULL pointers, because
sysctl(3) as used by kern.arandom ignores NULL oldp.  (This was caught by
getentropy(3) ATF tests.)

Reported by:	kib
Reviewed by:	kib
Discussed with:	delphij
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D14785
2018-03-21 23:52:37 +00:00
Conrad Meyer
e9ac27430c Implement getrandom(2) and getentropy(3)
The general idea here is to provide userspace programs with well-defined
sources of entropy, in a fashion that doesn't require opening a new file
descriptor (ulimits) or accessing paths (/dev/urandom may be restricted
by chroot or capsicum).

getrandom(2) is the more general API, and comes from the Linux world.
Since our urandom and random devices are identical, the GRND_RANDOM flag
is ignored.

getentropy(3) is added as a compatibility shim for the OpenBSD API.

truss(1) support is included.

Tests for both system calls are provided.  Coverage is believed to be at
least as comprehensive as LTP getrandom(2) test coverage.  Additionally,
instructions for running the LTP tests directly against FreeBSD are provided
in the "Test Plan" section of the Differential revision linked below.  (They
pass, of course.)

PR:		194204
Reported by:	David CARLIER <david.carlier AT hardenedbsd.org>
Discussed with:	cperciva, delphij, jhb, markj
Relnotes:	maybe
Differential Revision:	https://reviews.freebsd.org/D14500
2018-03-21 01:15:45 +00:00
John Baldwin
acf1f71044 Add a new set of simple tests for makecontext().
In contrast to the existing NetBSD setcontext_link test, these tests
verify that passing from 1 to 6 arguments through to the callback function
work correctly which can be useful for testing ABIs which split arguments
between registers and the stack.

Sponsored by:	DARPA / AFRL
2018-01-31 18:02:02 +00:00
Kyle Evans
b37f6c9805 Add libregex, connect it to the build
libregex is a regex(3) implementation intended to feature GNU extensions and
any other non-POSIX compliant extensions that are deemed worthy.

These extensions are separated out into a separate library for the sake of
not cluttering up libc further with them as well as not deteriorating the
speed (or lack thereof) of the libc implementation.

libregex is implemented as a build of the libc implementation with LIBREGEX
defined to distinguish this from a libc build. The reasons for
implementation like this are two-fold:

1.) Maintenance- This reduces the overhead induced by adding yet another
regex implementation to base.

2.) Ease of use- Flipping on GNU extensions will be as simple as linking
against libregex, and POSIX-compliant compilations can be guaranteed with a
REG_POSIX cflag that should be ignored by libc/regex and disables extensions
in libregex. It is also easier to keep REG_POSIX sane and POSIX pure when
implemented in this fashion.

Tests are added for future functionality, but left disconnected for the time
being while other testing is done.

Reviewed by:	cem (previous version)
Differential Revision:	https://reviews.freebsd.org/D12934
2018-01-22 02:44:41 +00:00
Alan Somers
82241ed55c Optimize telldir(3)
Currently each call to telldir() requires a malloc and adds an entry to a
linked list which must be traversed on future telldir(), seekdir(),
closedir(), and readdir() calls. Applications that call telldir() for every
directory entry incur O(n^2) behavior in readdir() and O(n) in telldir() and
closedir().

This optimization eliminates the malloc() and linked list in most cases by
packing the relevant information into a single long. On 64-bit architectures
msdosfs, NFS, tmpfs, UFS, and ZFS can all use the packed representation.  On
32-bit architectures msdosfs, NFS, and UFS can use the packed
representation, but ZFS and tmpfs can only use it for about the first 128
files per directory.  Memory savings is about 50 bytes per telldir(3) call.
Speedup for telldir()-heavy directory traversals is about 20-30x for one
million files per directory.

Reviewed by:	kib, mav, mckusick
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D13385
2017-12-06 22:06:48 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Bryan Drewery
3806950135 DIRDEPS_BUILD: Connect new directories.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:04:07 +00:00
Conrad Meyer
5a28df2e13 getmntinfo(3): Scale faster, and return sooner
getmntinfo(3) is designed around a relatively static or slow growing set of
current mounts.  It tried to detect a race with somewhat concurrent mount
and re-call getfsstat(2) in that case, looping indefinitely.  It also
allocated space for a single extra mount as slop.

In the case where the user has a large number of mounts and is adding them
at a rapid pace, it fell over.

This patch makes two functional changes:

1. Allocate even more slop.  Double whatever the last getfsstat(2) returned.

2. Abort and return some known results after looping a few times
   (arbitrarily, 3).  If the list is constantly changing, we can't guarantee
   we return a full result to the user at any point anyways.

While here, add very basic functional tests for getmntinfo(3) to the libc
suite.

PR:		221743
Submitted by:	Peter Eriksson <peter AT ifm.liu.se> (earlier version)
Sponsored by:	Dell EMC Isilon
2017-08-25 16:38:21 +00:00
Konstantin Belousov
25b73e6327 Improve standard compliance for memset_s() and abort_handler_s().
abort_handler_s() currently simply calls abort(), though the standard
specifies more: "Writes an implementation-defined message to stderr
which must include the string pointed to by msg and calls abort()."

memset_s() is missing error condition "n > smax", and does not invoke
the constraint handler after filling the buffer: "following errors are
detected at runtime and call the currently installed constraint
handler function after storing ch in every location of the destination
range [dest, dest+destsz) if dest and destsz are themselves valid",
one of the errors is "n > smax" itself.

Submitted by:	Yuri Pankov <yuripv@gmx.com>
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D11991
2017-08-12 15:18:17 +00:00
Pedro F. Giffuni
9404dae2a1 fnmatch(3): Update testcase for r322368. 2017-08-10 17:03:46 +00:00
Bryan Drewery
9f4bf11e12 Properly set userid for truncate_test.
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-07-21 16:14:06 +00:00
Alan Somers
eaca103d94 Fix cleanup in lib/libc/gen/setdomainname_test
ATF cleanup routines run in separate processes from the tests themselves, so
they can't share global variables.

Also, setdomainname_test needs to be is_exclusive because the test cases
access a global resource.

PR:		219967
Reviewed by:	ngie
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D11188
2017-07-06 14:47:59 +00:00
Will Andrews
c384464d25 tsearch_test: Test twalk & add some determinism. 2017-06-06 03:40:45 +00:00
Enji Cooper
ae442ee64a hostent_test_getaddrinfo_eq(..): call freeaddrinfo on ai when done
This plugs a leak of memory allocated via getaddrinfo.

MFC after:	1 week
Reported by:	Coverity
CID:		1346866
Sponsored by:	Dell EMC Isilon
2017-05-28 07:40:42 +00:00
Enji Cooper
dedafe6447 hostent_test_getnameinfo_eq(..): initialize found_a_host to false
MFC after:	1 week
Reported by:	Coverity
CID:		1368943
Sponsored by:	Dell EMC Isilon
2017-05-28 07:04:50 +00:00
Enji Cooper
49dd57f22d Bump WARNS from 1 to 3 after recent commits to fix warnings in the
directory.

Tested with:	clang 4.0, gcc 4.2.1, gcc 6.3.0
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-05-28 06:29:01 +00:00
Enji Cooper
8eb2367596 Push snapshot_file copying down into run_tests function, and mark snapshot_file
const char *.

This fixes a bogus set of errors from gcc about strdup not being allowed a NULL
argument.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-05-28 06:26:43 +00:00
Enji Cooper
e1f5475701 Fix a -Wunused-but-set-variable warning reported by gcc 6.3.0
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 05:31:18 +00:00
Enji Cooper
981aa50fc2 Fix -Wunused and -Wshadow warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 05:26:45 +00:00
Enji Cooper
91c53523fd getgr_test: fix -Wunused warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:43:02 +00:00
Enji Cooper
87a9deed3c getpw_test: fix -Wunused warnings
- Mark unused parameters __unused.
- Put dump_passwd under DEBUG as it's only used in that case.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:41:06 +00:00
Enji Cooper
58c03e4e08 gethostby_test: fix multiple warning types
- Fix -Wmissing-declaration warning by staticizing run_tests.
- Fix -Wsign-compare warnings by casting size_t types to int
  for comparisons.

Reindent some of the code in sdump_hostent(..) to accomodate the
overall changes.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:34:57 +00:00
Enji Cooper
42f519347e getproto_test: fix -Wunused warnings
Mark unused parameters __unused in functions.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:15:57 +00:00
Enji Cooper
eaff481c05 getrpc_test: fix -Wunused warnings
- Mark unused function parameters unused.
- Remove an unused function prototype.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:15:05 +00:00
Enji Cooper
2b19d77418 getserv_test: mark unused parameters __unused to fix corresponding
warnings

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:12:52 +00:00
Enji Cooper
93ee3b7e9b getusershell_test: mark mdata parameter in compare_usershell __unused
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:12:02 +00:00
Enji Cooper
bd8f63f25c getaddrinfo_test: mark unused function parameters __unused to fix -Wunused
warnings

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:11:04 +00:00
Enji Cooper
c4519040b5 getproto_test: fix -Wmissing-prototypes and -Wsign-compare warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:05:19 +00:00
Enji Cooper
8b0fc406e5 getrpc_test: fix -Wmissing-prototypes and -Wsign-compare warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:04:32 +00:00
Enji Cooper
905de51259 getaddrinfo_test: fix -Wsign-compare warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:03:45 +00:00
Enji Cooper
93936a0653 getserv_test: fix -Wsign-compare and -Wmissing-prototypes warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 04:03:06 +00:00
Enji Cooper
bbccc5a736 getusershell_test: staticize run_tests(..) to fix warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 03:58:36 +00:00
Enji Cooper
4a9a8952c0 Fix -Wsign-compare warnings
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 03:47:58 +00:00
Enji Cooper
bd874c6a7f Staticize functions and remove unused variables to aid with bumping WARNS
MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 03:42:49 +00:00
Enji Cooper
ae8cdfddc3 Sort make variables to suit style.Makefile(5)
This is being done prior to functional changes.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 03:39:24 +00:00
Enji Cooper
3bdd6cf05d lib/libc/tests/nss: use calloc appropriately
The pattern used prior to this commit was `calloc(1, n * sizeof(type))`;
the pattern that should be used however is `calloc(n, sizeof(type))`.

MFC after:	3 days
Sponsored by:	Dell EMC Isilon
2017-05-28 02:55:04 +00:00
Konstantin Belousov
fade31741d Add tests for some cases in r318298.
The first test triggers the out of bounds read of the 'left' array. It
only fails when realpath.c is compiled with '-fsanitize=address'.

The other test checks for ENOENT when running into an empty
symlink. This matches NetBSD's realpath(3) semantics. Previously,
empty symlinks were treated like ".".

Submitted by:	Jan Kokemц╪ller <jan.kokemueller@gmail.com>
PR:	219154
MFC after:	2 weeks
2017-05-18 13:49:53 +00:00
Conrad Meyer
241eb37e29 libc glob: Avoid pathological exponential behavior
Adapt glob's match() routine to use a greedy algorithm that avoids
exponential runtime in byzantine inputs.

While here, add a testcase for the byzantine input.

Prompted by:	https://research.swtch.com/glob
Authored by:	Yves Orton <demerphq at gmail.com>
Obtained from:	Perl (33252c318625f3c6c89b816ee88481940e3e6f95)
Sponsored by:	Dell EMC Isilon
2017-05-03 15:55:29 +00:00
Baptiste Daroussin
c48dc2a193 Fix strcoll_l disagreeing with strxfrm by reworking the forward order case in
wcscoll_l().

Illumos fixed this while grabbing back our patches:
https://www.illumos.org/rb/r/402/

This does not 100% fix what postgresql folks reported as there is still a
remaining issue: https://www.illumos.org/issues/7962, it improves the situation

The initial issue was reported in postgresql mailing lists:
https://www.postgresql.org/message-id/flat/111D0E27-A8F3-4A84-A4E0-B0FB703863DF@s24.com#111D0E27-A8F3-4A84-A4E0-B0FB703863DF@s24.com

Submitted by:	Yuri Pankov <yuri.pankov@nexenta.com>
Obtained from:	Illumos
MFC after:	2 weeks
2017-04-16 19:12:07 +00:00
Konstantin Belousov
9851b3400a Implement the memset_s(3) function as specified by the C11 ISO/IEC
9899:2011 Appendix K 3.7.4.1.

Other needed supporting types, defines and constraint_handler
infrastructure is added as specified in the C11 spec.

Submitted by:	Tom Rix <trix@juniper.net>
Sponsored by:	Juniper Networks
Discussed with:	ed
MFC after:	3 weeks
Differential revision:	https://reviews.freebsd.org/D9903
Differential revision:	https://reviews.freebsd.org/D10161
2017-03-30 04:57:26 +00:00
Enji Cooper
fd752a71ce Don't build/install lib/libc/io_test anymore
The failing test requires the zh_TW.Big5 locale, which is no longer
installed as of r315568.

Add a note/pointer just in case someone considers re-adding it.

Reported by:	Jenkins
Sponsored by:	Dell EMC Isilon
2017-03-20 03:50:22 +00:00
Eric van Gyzen
3f8455b090 Add clock_nanosleep()
Add a clock_nanosleep() syscall, as specified by POSIX.
Make nanosleep() a wrapper around it.

Attach the clock_nanosleep test from NetBSD. Adjust it for the
FreeBSD behavior of updating rmtp only when interrupted by a signal.
I believe this to be POSIX-compliant, since POSIX mentions the rmtp
parameter only in the paragraph about EINTR. This is also what
Linux does. (NetBSD updates rmtp unconditionally.)

Copy the whole nanosleep.2 man page from NetBSD because it is complete
and closely resembles the POSIX description. Edit, polish, and reword it
a bit, being sure to keep any relevant text from the FreeBSD page.

Reviewed by:	kib, ngie, jilles
MFC after:	3 weeks
Relnotes:	yes
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D10020
2017-03-19 00:51:12 +00:00