Commit Graph

7549 Commits

Author SHA1 Message Date
Konstantin Belousov
670afb84e3 MFC r306334:
Document thr_suspend(2) and thr_wake(2).

MFC r306506:
Reword the statement.
2016-10-03 09:32:19 +00:00
Andrey A. Chernov
aa8ee22733 MFC r306075,r306109
1) Microoptimize %p case.
2) Implememt %u for GNU compatibility.
3) Don't forget to advance buf for %w/%u.
4) Fail with incomplete week (week 0) request and no such week in the
year.
5) Fix yday formula when Sunday requested and the week started from Monday.
6) Fail with impossible yday for incomplete week (week 0) and direct %w/%u
request.
7) Shift yday/wday to the first day of the year, if incomplete week
(week 0) requested and no %w/%u used.
8) For already non-standard %z extension implement GNU compatible formats:
+hh and -hh.
9) Check for incorrect values for %z.

PR:     212983 (case 3 only)
2016-09-28 20:49:33 +00:00
Sergey Kandaurov
a23aa7881b MFC r274925: misc mdoc fixes. 2016-09-27 19:00:22 +00:00
Eric Badger
9f1c875e02 MFC r305956: Add manpage for rctl_* system calls
Approved by:	kib (mentor)
Sponsored by:	Dell Technologies
2016-09-24 16:46:37 +00:00
Pedro F. Giffuni
b8944b9039 MFC r303889:
libc/rpc: replace comma with semicolon when pertinent.

Uses of commas instead of a semicolons can easily go undetected. The comma
can serve as a statement separator but this shouldn't be abused when
statements are meant to be standalone.
2016-09-08 15:12:55 +00:00
Andrey A. Chernov
11d068f019 MFC r305413
Fix error handling.
2016-09-08 07:14:48 +00:00
Andrey A. Chernov
983e3d1a9e MFC r305406,r305409,r305412
1) Fix errors handling.

2) Prevent out of bounds access to ws[-1] (passed buffer) which happens
when the first mb sequence is incomplete and there are not enougn chars in
the read buffer. ws[-1] may lead to memory faults or false results, in
case the memory here contains '\n'.

3) Fix n == 1 case. Here should be no physical read (fill buffer) attempt
(we read n - 1 chars with the room for NUL, see fgets()),
and no NULL return.
2016-09-08 05:13:50 +00:00
Jilles Tjoelker
bc02a08b43 MFC r305154: directory(3): Deprecate readdir_r(). Clarify dirent buffers.
In existing implementations including FreeBSD, there is no reason to use
readdir_r() in the common case where potentially multiple threads each list
their own directory. Code using readdir() is simpler.

What's more, although readdir_r() can safely be used on FreeBSD because
NAME_MAX is forced to 255, it cannot be used safely on systems where
{NAME_MAX} is not fixed. As a concrete example, FAT/NTFS filenames can be up
to 255 UTF-16 code units long, which can be up to 765 UTF-8 bytes.

Deprecating readdir_r() in POSIX has been proposed in
http://www.austingroupbugs.net/view.php?id=696
and glibc wants to deprecate it as well.
2016-09-07 21:09:44 +00:00
Jilles Tjoelker
3562b6fbff MFC r305090: getvfsbyname(3): Remove [EFAULT] error.
Since r101651 in 2002, getvfsbyname() has written *vfc using userland
memcpy(), so the [EFAULT] error no longer occurs.
2016-09-07 21:04:39 +00:00
Andrey A. Chernov
3b48425e45 MFC r305241
fgetwc(3) may set both __SEOF and __SERR at once (in case of incomplete
sequence near EOF), so we can't just check for
(wc == WEOF && !__sfeof(fp)) and must relay on __sferror(fp) with
__SERR clearing/restoring.
2016-09-05 01:57:32 +00:00
Andrey A. Chernov
69fc65f5cb MFC r305144
'addrlen' does not matter when we need to find the first non-zero bit in
the byte from the left and 'addrlen' already counted in 'lim'.

PR:     212121
Submitted by:   Herbie.Robinson@stratus.com
2016-09-05 00:36:52 +00:00
Andrey A. Chernov
ead6c07827 MFC r305219
If error happens, don't overwrite original errno comes from __mbrtowc()
and __srefill().
2016-09-04 00:34:15 +00:00
Konstantin Belousov
4dce45583e MFC r304928:
Do not obliterate errno value in the main thread during ptrace(2) call on x86.

MFC r304931:
Follow ABI when calling __error from the ptrace(2) wrapper.

MFC r305012:
Rewrite ptrace(2) wrappers in C.

MFC r305022:
Restore the requirement of setting errno to zero before calling ptrace(2).
2016-09-03 11:09:47 +00:00
Andrey A. Chernov
5c0f6f97b0 MFC r305133
Apply the same qsort() usage fix as in r304911 getaddrinfo.c
qsort() can't be stabilized with just return(-1) alone.
2016-09-03 01:08:52 +00:00
Enji Cooper
a336dc1bda MFstable/11 r304950:
MFC r304033:

Increase timeout from 10 minutes to 20 minutes for all tests

On particular slow networks, it can (on average) take longer to
resolve hosts to IP* addresses. 20 minutes seemed reasonable for
my work network

This will be solved in a more meaningful way (if possible) using
concurrency in the near future
2016-09-02 04:12:36 +00:00
Konstantin Belousov
3284c1bc8a MFC r305024:
Typesetting fixes.
2016-09-01 07:23:47 +00:00
Andrey A. Chernov
4b5568e830 MFC r304911
The formal behavior of qsort is unstable with regard to objects that
are equal. Unfortunately, RFC 3484 requires that otherwise equal objects
remain in the order supplied by the DNS server. The present code attempts
to deal with this by returning -1 for objects that are equal (i.e.,
returns that the first parameter is less then the second parameter).
Unfortunately, the qsort API does not state that the first parameter
passed in is in any particular position in the list.

PR:     212122
Submitted by:   Herbie.Robinson@stratus.com
2016-08-30 00:57:57 +00:00
Enji Cooper
c9d782aae1 MFstable/11 r304945:
MFC r304034:

Initialize `ai` to NULL and test for `ai` with type-appropriate values

Depending on the address family and ai_flags containing AI_V4MAPPED,
it might not do a proper DNS lookup on the provided DNS address

Convert some `ai` boolean true/false checks to NULL/non-NULL while here.

PR:		211790
2016-08-29 05:46:35 +00:00
Andrey A. Chernov
46164b0d99 MFC r304607,r304641,r304819,r304811
1) Don't forget to set __SERR on __slbexpand() error.

2) Remove "Fast path" from fgetwc()/fputwc() since it can't detect
encoding errors and ignores them all.
One of affected encoding example: US-ASCII

3)  Original fgetln() from 44lite return success for line tail errors,
i.e. partial line, but set __SERR and errno in the same time, which
is inconsistent.
Now both OpenBSD and NetBSD return failure, i.e. no line and set error
indicators for such case, so make our fgetln() and fgetwln()
(as its wide version) compatible with the rest of *BSD.

PR:     212033
2016-08-27 10:34:01 +00:00
Andrey A. Chernov
470eb23810 MFC r304810
Don't check for __SERR which may stick from one of any previous stdio
functions.
__SERR is for user and the rest of stdio code do not check it
for error sensing internally, only set it.
In vf(w)printf.c here it is more easy to save __SERR, clear and restore it.
2016-08-27 09:58:06 +00:00
Andrey A. Chernov
0c2af93e3a MFC r304703, r304755
1) _locale.h
LC_*_MASK bit shifting order was partially broken from the initial commit
time at year 2012. Only LC_COLLATE_MASK and LC_CTYPE_MASK are in the
right order.

The order here should match XLC_* from "xlocale_private.h" which, in turn,
match LC_* publicly visible order from <locale.h> which determines how
locale components are stored in the structure.
LC_*_MASK -> XLC_* translation done as "ffs(mask) - 1" in the querylocale()
and equivalent shift loop in the newlocale(), so mapped to some wrong
components (excluding two mentioned above).

Formally the fix is ABI breakage, but old code using those masks
never works properly in any case.
Only newlocale() and querylocale() are affected.

2) msgcat.c
Use current locale (f.e. set by thread). It was global locale always
previously.

PR:     211743
2016-08-26 21:19:23 +00:00
Andrey A. Chernov
45d126dc75 MFC r295632
getln: We cannot expand the buffer beyond INT_MAX (_size overflows).

In such cases return ENOMEM. This is a limitation of our
implementation, alternatively you may consider getline(3).

Differential Revision:  https://reviews.freebsd.org/D442 (Partial)
Obtained from:  Apple Inc. (Libc 997.90.3)
2016-08-25 19:55:31 +00:00
Andrey A. Chernov
6a2a362030 Direct commit, equal to MFC part of r295632 which is not planned for
MFC at whole.
Set __SERR on  __slbexpand() errors.
2016-08-23 00:00:06 +00:00
John Baldwin
7a286296b4 MFC 304476: Fix various nits in the aio operation manpages.
- Avoid double use of "request" in a single sentence.  Instead, describe
  aio_sigevent as being used to request notification of the associated
  operation's completion.  This matches the language used to describe
  aio_sigevent in aio(4).
- Simplify the prohibition on modifying buffers while requests are in
  flight.
- Fix case mismatch.
- Drop note about not using stack variables. C programmers should be able
  to figure out if a stack variable is safe based on the later warning
  about the life cycle requirements of control blocks.
- Remove prohibition on modifying the I/O buffer for aio_fsync() since
  it does not use an I/O buffer.  For aio_mlock(), prohibit modifications
  to the mapping (e.g. due to mprotect, munmap, mmap, etc.) but do not
  prohibit modifications to the memory backing the buffer (stores into
  the pages backing the buffer).
2016-08-22 17:52:10 +00:00
Enji Cooper
8e5fd0c9c5 Unbreak the build when MK_TESTS != no after r304527
- src.opts.mk should be bsd.own.mk on ^/stable/10
- LIBADD should be DPADD/LDADD on ^/stable/10

Pointyhat to:	kib
Reported by:	Olivier Pinter <oliver.pinter@hardenedbsd.org>
Sponsored by:	EMC / Isilon Storage Division
2016-08-21 05:08:37 +00:00
Konstantin Belousov
bde29dbe4c MFC r303795:
Add __cxa_thread_atexit(3) API implementation.
2016-08-20 12:26:44 +00:00
Konstantin Belousov
88c052e98e MFC r303794:
Create namespace for the symbols added during 12-CURRENT cycle.
2016-08-20 12:23:27 +00:00
John Baldwin
fe0654c31f MFC 303001: Add PTRACE_VFORK to trace vfork events.
First, PL_FLAG_FORKED events now also set a PL_FLAG_VFORKED flag when
the new child was created via vfork() rather than fork().  Second, a
new PL_FLAG_VFORK_DONE event can now be enabled via the PTRACE_VFORK
event mask.  This new stop is reported after the vfork parent resumes
due to the child calling exit or exec.  Debuggers can use this stop to
reinsert breakpoints in the vfork parent process before it resumes.
2016-08-19 20:17:57 +00:00
Andrey A. Chernov
43a1a44640 MFC r302943,r302944,r303004,r303010,r303011,r303013,r303014,r303074,
r303088,r303142,r303208,r303210,r303530,r303536,r303564,r303565,
    r303706

In short:

1) All situations with glob(3) error return codes are well defined by
POSIX, so rewrite old sporadic errors processing to match those
definitions.

Including subcases:

Both C99 and POSIX directly prohibits any standard function to set errno
to 0. Breaking this rule in 2001 NetBSD hack was imported which attempts
to workaround very limited glob(3) return codes amount.
Use POSIX-compatible workaround now with E2BIG which can't comes from
other functions used instead of prohibited 0.

Process errors happpens in (*readdirfunc)() too, as POSIX requires.

Per POSIX GLOB_NOCHECK should return original pattern,
unmodified, if no matches found. But our code strips all '\'
returning it. Rewrite the code to allow to return original pattern.

GLOB_ERR and gl_errfunc are supposed to work only for real directories
per POSIX, so don't act on missing or plain files for ENOENT or ENOTDIR
(as TODO in the code suggested).
Remove the hack in the manpage describing how to skip ENOENT and ENOTDIR
in gl_errfunc, it is unneeded now.

Per POSIX GLOB_ERR must be considered even if gl_errfunc is not set,
old code skips it in that case.

2) For near MAXPATHLEN long pathes old glob(3) code can operate on
truncated results, prevent it in several places.

3) Results was not sorted according to collate as POSIX requires.

4) globtilde() forget to convert expanded user home dir from multibyte to
wide chars. Moreover, those chars are addded as not protected, so
can be treated as special chars.

5) Backward hack for EILSEQ in g_Ctoc() was not implemented, so all
pathes with illegal byte sequences are skipped as result, implement it now.

6) GLOB_BRACE was somehow broken. First it repeatedly calls glob0() in
globexp1() recursive calls, but glob0() was not supposed to be called
repeatedly in the original code. It finalize results by possible adding
original pattern for no match case, may return GLOB_NOMATCH error and
by sorting all things. Original pattern adding or GLOB_NOMATCH error
can happens each time glob0() called repeatedly, and sorting happens
for one item only, all things are never sorted. Second, f.e. "a{a"
pattern does not match "a{a" file but match "a" file instead.
Third, some errors (f.e. for limits or overflow) can be ignored
by GLOB_BRACE code because it forces return (0).

Add non-finalizing flag to glob0() and make globexp0() wrapper around
recursively called globexp1() to finalize things like glob0() does.
Reorganize braces code to work correctly.

7) Don't allow MB_CUR_MAX * strlen overallocation hits GLOB_LIMIT_STRING
(ARG_MAX) limit, use final string length, not malloced space for it.
2016-08-16 07:14:09 +00:00
John Baldwin
6c57684dd2 MFC 302900,302902,302921,303461,304009:
Add a mask of optional ptrace() events.

302900:
Add a test for user signal delivery.

This test verifies we get the correct ptrace event details when a signal
is posted to a traced process from userland.

302902:
Add a mask of optional ptrace() events.

ptrace() now stores a mask of optional events in p_ptevents.  Currently
this mask is a single integer, but it can be expanded into an array of
integers in the future.

Two new ptrace requests can be used to manipulate the event mask:
PT_GET_EVENT_MASK fetches the current event mask and PT_SET_EVENT_MASK
sets the current event mask.

The current set of events include:
- PTRACE_EXEC: trace calls to execve().
- PTRACE_SCE: trace system call entries.
- PTRACE_SCX: trace syscam call exits.
- PTRACE_FORK: trace forks and auto-attach to new child processes.
- PTRACE_LWP: trace LWP events.

The S_PT_SCX and S_PT_SCE events in the procfs p_stops flags have
been replaced by PTRACE_SCE and PTRACE_SCX.  PTRACE_FORK replaces
P_FOLLOW_FORK and PTRACE_LWP replaces P2_LWP_EVENTS.

The PT_FOLLOW_FORK and PT_LWP_EVENTS ptrace requests remain for
compatibility but now simply toggle corresponding flags in the
event mask.

While here, document that PT_SYSCALL, PT_TO_SCE, and PT_TO_SCX both
modify the event mask and continue the traced process.

302921:
Rename PTRACE_SYSCALL to LINUX_PTRACE_SYSCALL.

303461:
Note that not all optional ptrace events use SIGTRAP.

New child processes attached due to PTRACE_FORK use SIGSTOP instead of
SIGTRAP.  All other ptrace events use SIGTRAP.

304009:
Remove description of P_FOLLOWFORK as this flag was removed.
2016-08-15 21:10:41 +00:00
John Baldwin
b0fbcc609d MFC 292894,292896: Add ptrace(2) reporting for LWP events.
292894:
Add ptrace(2) reporting for LWP events.

Add two new LWPINFO flags: PL_FLAG_BORN and PL_FLAG_EXITED for reporting
thread creation and destruction. Newly created threads will stop to report
PL_FLAG_BORN before returning to userland and exiting threads will stop to
report PL_FLAG_EXIT before exiting completely. Both of these events are
only enabled and reported if PT_LWP_EVENTS is enabled on a process.

292896:
Document the recently added support for ptrace(2) LWP events.
2016-08-12 19:43:06 +00:00
Mark Johnston
aa98810380 MFC r301710:
Fix an infinite loop in setnetgrent(3) with NIS netgroups.
2016-08-02 21:17:34 +00:00
John Baldwin
7960b5179f MFC 302899: Add documentation for the sigevent structure.
- Add a sigevent(3) manpage to give a general overview of the sigevent
  structure and the available notification mechanisms.
- Document that AIO requests contain a nested sigevent structure that can
  be used to request completion notification.
- Expand the sigevent details in other manuals to note details such as
  the extra values stored in a queued signal's information or in a posted
  kevent.
2016-07-25 23:38:14 +00:00
Andrey A. Chernov
9e690816f8 Forget to merge this changes in prev. MFC 2016-07-22 16:48:39 +00:00
Andrey A. Chernov
bb01f2c588 MFC: r302824
1) Eliminate possibility to call __*collate_range_cmp() with inclomplete
locale (which cause core dump) by removing whole 'table' argument
by which it passed.

2) Restore __collate_range_cmp() in __sccl().

3) Collating [a-z] range in regcomp() works for single byte locales only
(we can't do it for other ones). In previous state only first 256
wide chars are considered and all others are just silently dropped from the
range.
2016-07-22 14:24:17 +00:00
Enji Cooper
afa3d073c5 MFC r301708:
Revert r301707

getnetent_p doesn't return NULL like getnetent does. coccinelle got confused and
I didn't verify that it worked before committing the change

Pointyhat to: ngie
2016-07-08 19:13:18 +00:00
Enji Cooper
946b5b5065 MFC r301707:
Use NULL instead of `0` in _ht_getnetbyname(..)

- getnetent returns NULL on completion/error.
- .h_aliases is NULL terminated.
2016-07-08 19:04:51 +00:00
Ed Schouten
d2025d4cdf MFC r300775:
Let l64a() properly null terminate its result.

  Though the buffer used by l64a() is initialized with null bytes,
  repetetive calls may end up having trailing garbage of previous
  invocations because we don't end up terminating the string.

  Instead of importing NetBSD's fix, use this opportunity to simplify this
  function dramatically, for example by just storing the Base64 character
  set in a string. There is also no need to do the bitmasking, as we can
  just use the proper integer type from <stdint.h>.
2016-06-25 10:08:04 +00:00
Pedro F. Giffuni
f5e10edb19 MFC r300683:
libc: regexec(3) adjustment.

Change the behavior of when REG_STARTEND is combined with REG_NOTBOL.

From the original posting[1]:

"Enable the assumption that pmatch[0].rm_so is a continuation offset
to  a string and allows us to do a proper assessment of the character
in  regards to it's word position ('^' or '\<'), without risking going
into unallocated memory."

This change makes us similar to how glibc handles REG_STARTEND |
REG_NOTBOL, and is closely related to a soon-to-land fix to sed.

Special thanks to Martijn van Duren and Ingo Schwarze for working
out some consistent behaviour.

Differential Revision:	https://reviews.freebsd.org/D6257
Taken from:	openbsd-tech 2016-05-24 [1]  (Martijn van Duren)
2016-06-24 02:24:34 +00:00
Don Lewis
90fe82cd3b MFC r301596
Don't leak olinep if malloc() fails.

If malloc() fails to allocate linep, then free olinep (if it exists)
before returning to avoid a memory leak.

Reported by:	Coverity
CID:		1016716
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D6755
2016-06-15 06:42:30 +00:00
Don Lewis
14b15f6ce4 MFC r301592
Don't leak addrinfo if ai->ai_addrlen <= minsiz test fails.

If the ai->ai_addrlen <= minsiz test fails, then freeaddrinfo()
does not get called to free the memory just allocated by getaddrinfo().
Fix by moving ai->ai_addrlen <= minsiz to a separate nested if
block, and keep freeaddrinfo() in the outer block so that freeaddrinfo()
will be called whenever getaddrinfo() succeeds.

Reported by:	Coverity
CID:		1273652
Reviewed by:	ume
Differential Revision:	https://reviews.freebsd.org/D6756
2016-06-15 06:40:30 +00:00
Jamie Gritton
e2091b5648 MFC r300983:
Mark jail(2), and the sysctls that it (and only it) uses as deprecated.
  jail(8) has long used jail_set(2), and those sysctl only cause confusion.
2016-06-15 01:49:01 +00:00
Enji Cooper
084892944d MFC r301704:
Test for strchr(3) returning NULL, not 0
2016-06-11 01:37:59 +00:00
Enji Cooper
787d8204b0 MFC r299511:
r299511 (by cem):

print_positional_test: Fix misuse of wchar APIs

These APIs take unit length, not byte length parameters.

CIDs:		1338543, 1338544, 1338545
2016-06-10 18:13:41 +00:00
Enji Cooper
83ac1c0f69 MFC r299502:
r299502 (by cem):

nss/gethostby_test: fix broken vector iteration of gethostbyaddr h_aliases

h_aliases is a NULL-terminated rather than fixed-length array.  nitems() is not
a valid way to determine its end; instead, check for NULL.

CID:		1346578
2016-06-10 15:42:17 +00:00
Enji Cooper
f5ad798316 MFC r300624:
Fix up r300385

I accidentally glossed over the fact that tmp is manipulated via strchr, so
if we tried to free `tmp` after r300385, it would have crashed.

Create a separate pointer (tmp2) to track the original allocation of `tmp`,
and free `tmp2` if `p->nc_lookups` can't be malloced

CID: 1356026
2016-06-08 18:46:10 +00:00
Enji Cooper
21ab1d8839 MFC r300385:
Don't leak `tmp` if `p->nc_lookups` can't be malloced
2016-06-08 18:41:49 +00:00
Enji Cooper
40b2787d58 MFC r300386:
Don't leak `handle` if svc_tp_create(..) succeeds and allocating a new
struct xlist object fails

CID: 978277
2016-06-08 18:27:44 +00:00
Enji Cooper
4aab7009d5 MFC r300387,r300388,r300389:
r300387:

getnetid(..): consistently fclose fd at the end of the function

This mutes a false positive with cppcheck, but also helps eliminate future
potential issues with this variable

r300388:

Call endnetconfig on nc_handle sooner to avoid leaking nc_handle if tmpnconf
was NULL

This would theoretically happen if the netconfig protocol family and protocol
semantics were never matched.

CID: 978179

r300389:

nis_rpcent: don't leak resultbuf from yp_first(..)/yp_next(..)

If the buffer couldn't be adequately resized to accomodate an additional "\n",
it would leak resultbuf by breaking from the loop early

CID: 1016702
2016-06-08 14:18:47 +00:00
Enji Cooper
02597a9664 MFC r300620,r300621:
r300620:

Use reallocf instead of malloc to fix leak with outbuf_pmap

The previous code overwrote outbuf_pmap's memory with malloc once per
loop iteration, which leaked its memory; use reallocf instead to ensure
that memory is properly free'd each loop iteration.

Add a outbuf_pmap = NULL in the failure case to avoid a double-free
at the bottom of the function.

CID: 1038776

r300621:

Remove redundant NULLing of outbuf_pmap

If reallocf ever failed, outbuf_pmap would already be NULL
2016-06-08 13:58:47 +00:00