Commit Graph

1771 Commits

Author SHA1 Message Date
Pedro F. Giffuni
b3d078e666 compat_passwd(): yet another uninitialized access to stayopen.
CID:	1018731
2015-03-06 22:22:57 +00:00
Jilles Tjoelker
c317cb51b2 nice(): Put back old return value, keeping [EPERM] error.
Commit r279154 changed the API and ABI significantly, and {NZERO} is still
wrong.

Also, preserve errno on success instead of setting it to 0.

PR:		189821
Reported by:	bde
Relnotes:	yes
2015-02-28 18:22:10 +00:00
Konstantin Belousov
eb75dcc07b Fix typo. Note that this is mostly innocent, since libthr no longer
interposes the symbol.

Noted by:	rpaulo
MFC after:	3 days
2015-02-27 19:23:01 +00:00
Pedro F. Giffuni
e382e86bb4 setmode(3): Make sure that setmode sets errno on failure.
Our man page already documented this partially but now
we have some consistent behavior.

PR:		136669
Obtained from:	NetBSD (CVS rev. 1.31, 1.33)
Relnotes:	yes
MFC after:	3 weeks
2015-02-22 20:16:44 +00:00
Jilles Tjoelker
e220ce08ef nice(): Correct return value and [EPERM] error.
PR:		189821
Obtained from:	NetBSD
Relnotes:	yes
2015-02-22 13:36:44 +00:00
Pedro F. Giffuni
0b7361b3e3 tab vs spaces. 2015-02-20 20:27:53 +00:00
Pedro F. Giffuni
a69a20fa13 Fix small memleaks in nis_passwd() and nis_group().
These only occur upon error.

Code Review:	https://reviews.freebsd.org/D1849
Reviewed by:	delphij

CID:	1016715
CID:	1016717
2015-02-20 01:02:32 +00:00
Pedro F. Giffuni
d2f783303b ulimit(3): simplify.
rlim_t is at least as large as long, so we don't need the
extra variable to keep the intermediate step. We don't
need the volatile either.

The code was tested on i386 and amd64.

Suggested by:	bde
X-MFC with:	r278803
2015-02-17 16:01:00 +00:00
Pedro F. Giffuni
78a452c36e Replace strcpy() with strlcpy()
The risk of an overrun here is very low but check the
length, JIC.

CID:	1019039
2015-02-15 21:11:07 +00:00
Pedro F. Giffuni
1a4161a15d Reverse one of the initializations from r278804.
It does no harm but this is not needed after the
correction in r278805 and I prefer to keep this
code very similar to it's original state.
2015-02-15 21:03:49 +00:00
Pedro F. Giffuni
b78ceb0a58 Mismatch in r278804. 2015-02-15 18:02:05 +00:00
Pedro F. Giffuni
09cc2762fa More tidy-ups on uninitialized scalar variable
As a followup to r278363, there is one more case where
stayopen can be accessed uninitialized, but even after
swapping arguments, access is possible in some other
cases so prevent it completely by initializing stayopen.

CID:	1018729
CID:	1018732
2015-02-15 16:50:21 +00:00
Pedro F. Giffuni
e291429c5b ulimit(3): Fix broken check.
The existing implementation had a broken comparison that could
overflow and return confusing values.  Replace this with a check
that avoids the overflow before it happens.

Consistently return a maximum value also on the case of negative
arguments since negative is considered an overflow and means
infinity for our current setrlimit().

New revamped version is credited to Bruce Evans.

CID:		1199295
MFC after:	1 week
2015-02-15 14:31:50 +00:00
Tijl Coosemans
dac0a53840 The ld(1) flag is -Bsymbolic not -Wsymbolic. 2015-02-14 15:14:41 +00:00
Konstantin Belousov
45468c5356 Properly interpose libc spinlocks, was missed in r276630. In
particular, stdio locking was affected.

Reported and tested by:	"Matthew D. Fuller" <fullermd@over-yonder.net>
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2015-02-14 11:47:40 +00:00
Pedro F. Giffuni
09d73a0662 Revert 278634: This broke the build due to the compiler being too clever.
Will be back, with proper compiler workarounds.
2015-02-13 00:21:54 +00:00
Pedro F. Giffuni
0b44c6cc6e ulimit(3): Fix broken check.
The existing implementation had a broken comparison that could overflow.
Replace this with a check that avoids the overflow before it happens.

Consistently return a maximum value also on the case of negative
arguments since negative is considered an overflow and means
infinity for our current setrlimit().

Discussed with:	bde (rather extensively)

CID:		1199295
MFC after:	1 week
2015-02-12 21:07:42 +00:00
Pedro F. Giffuni
eb77fbdcec Protect uninitialized scalar variable from being accessed
In a couple of cases a variable "stayopen" can be checked
unitialized. This is of no danger as the complementary
condition is false but prevent the access by switching
the checks.

CID:	1018729
CID:	1018732
2015-02-07 19:51:34 +00:00
Pedro F. Giffuni
24ef1d7ab6 Drop cgetclose() from getdiskbyname().
This was a local addition to the original change from NetBSD.
Being this libc there is some chance for it to interfere with
user's cget*() functions usage. The memory leak was finely
plugged by r278300.

Pointed out by:	ache
2015-02-06 14:07:01 +00:00
Pedro F. Giffuni
5262b957d4 getdiskbyname(): plug resource leak
Variable cq going out of scope leaks the storage it points to.

CID:		270511
Phabric:	D1775
Reviewed by:	imp
Obtained from:	NetBSD (CVS rev. 1.34)
MFC after:	2 weeks
2015-02-05 22:54:31 +00:00
Jilles Tjoelker
424c16b2ce ttyname_r(): Return actual error, not always [ENOTTY].
Adjust the test that used to fail because of this bug.

PR:		191936
MFC after:	1 week
2015-02-01 22:50:33 +00:00
Jilles Tjoelker
49ba8a68f0 sem_post(): Fix and document semaphore value overflow error.
The error code is per Austin Group issue #315.

I provided different wording for the manual page change.

Submitted by:	pluknet
MFC after:	1 week
2015-01-28 22:42:56 +00:00
Ed Maste
4b12fb6103 Remove duplicate copies of trivial getcontextx.c
Only i386 and amd64 provide a non-trivial __getcontextx(). Use a common
trivial implementation in gen/ for other architectures, rather than
copying the file to each MD subdirectory.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D1472
2015-01-12 18:13:38 +00:00
Konstantin Belousov
397d851d66 Reduce the size of the interposing table and amount of
cancellation-handling code in the libthr.  Translate some syscalls
into their more generic counterpart, and remove translated syscalls
from the table.

List of the affected syscalls:
creat, open -> openat
raise -> thr_kill
sleep, usleep -> nanosleep
pause -> sigsuspend
wait, wait3, waitpid -> wait4

Suggested and reviewed by:	jilles (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2015-01-11 22:16:31 +00:00
Craig Rodrigues
9cebfb86a7 Clarify text to be consistent with nanosleep(2),
since sleep(3) is implemented in terms of nanosleep(2).

This is similar to the sleep(3) man page for Darwin.
2015-01-08 01:27:43 +00:00
Konstantin Belousov
8495e8b1e9 Fix known issues which blow up the process after dlopen("libthr.so")
(or loading a dso linked to libthr.so into process which was not
linked against threading library).

- Remove libthr interposers of the libc functions, including
  __error(). Instead, functions calls are indirected through the
  interposing table, similar to how pthread stubs in libc are already
  done.  Libc by default points either to syscall trampolines or to
  existing libc implementations.  On libthr load, libthr rewrites the
  pointers to the cancellable implementations already in libthr.  The
  interposition table is separate from pthreads stubs indirection
  table to not pull pthreads stubs into static binaries.

- Postpone the malloc(3) internal mutexes initialization until libthr
  is loaded.  This avoids recursion between calloc(3) and static
  pthread_mutex_t initialization.

- Reinstall signal handlers with wrapper on libthr load.  The
  _rtld_is_dlopened(3) is used to avoid useless calls to sigaction(2)
  when libthr is statically referenced from the main binary.

In the process, fix openat(2), swapcontext(2) and setcontext(2)
interposing.  The libc symbols were exported at different versions
than libthr interposers.  Export both libc and libthr versions from
libc now, with default set to the higher version from libthr.

Remove unused and disconnected swapcontext(3) userspace implementation
from libc/gen.

No objections from:	deischen
Tested by:	pho, antoine (exp-run) (previous versions)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2015-01-03 18:38:46 +00:00
Konstantin Belousov
0e521992a4 Add rtld private interface for dso to detect dynamic loading
vs. static linking.

Tested by:	pho, antoine (exp-run)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2015-01-03 18:09:53 +00:00
Christian Brueffer
0aee91e1fb Various mdoc fixes and a few EOL whitespace removals.
Found with:	mandoc -Tlint
2014-12-21 12:36:36 +00:00
Xin LI
52e05d9a24 Reinstitate send() after syslogd restarts.
In r228193 the test of CONNPRIV have been moved to before the _usleep
and send in vsyslog().  When syslogd restarts, this would prevent the
message being logged after the disconnect/connect dance for
scenario #1.

PR:		194751
Submitted by:	Peter Creath <pjcreath+freebsd gmail com>
Reviewed By:	glebius
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D1227
2014-11-25 20:59:22 +00:00
Ed Maste
294246bb7d Revert r274772: it is not valid on MIPS
Reported by:	sbruno
2014-11-25 03:50:31 +00:00
Ed Maste
688fd61ae8 Use canonical __PIC__ flag
It is automatically set when -fPIC is passed to the compiler.

Reviewed by:	dim, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1179
2014-11-21 02:05:48 +00:00
Mark Johnston
20cc9ac42f getgrouplist(3) was reimplemented in terms of getgrent_r(3) in r174547, so
this bug is no longer valid.

MFC after:	3 days
2014-10-27 04:09:23 +00:00
John Baldwin
53e1ffbbce The current POSIX semaphore implementation stores the _has_waiters flag
in a separate word from the _count.  This does not permit both items to
be updated atomically in a portable manner.  As a result, sem_post()
must always perform a system call to safely clear _has_waiters.

This change removes the _has_waiters field and instead uses the high bit
of _count as the _has_waiters flag.  A new umtx object type (_usem2) and
two new umtx operations are added (SEM_WAIT2 and SEM_WAKE2) to implement
these semantics.  The older operations are still supported under the
COMPAT_FREEBSD9/10 options.  The POSIX semaphore API in libc has
been updated to use the new implementation.  Note that the new
implementation is not compatible with the previous implementation.
However, this only affects static binaries (which cannot be helped by
symbol versioning).  Binaries using a dynamic libc will continue to work
fine.  SEM_MAGIC has been bumped so that mismatched binaries will error
rather than corrupting a shared semaphore.  In addition, a padding field
has been added to sem_t so that it remains the same size.

Differential Revision:	https://reviews.freebsd.org/D961
Reported by:	adrian
Reviewed by:	kib, jilles (earlier version)
Sponsored by:	Norse
2014-10-24 20:02:44 +00:00
John Baldwin
15096da3f4 Don't reference sem(4) from the POSIX semaphore pages. POSIX semaphores
were reimplemented using umtx in FreeBSD 9 and no longer use sem(4).
2014-10-24 19:55:49 +00:00
Ed Maste
a6897b9320 Update dl_iterate_phdr(3) to follow r272842
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
2014-10-09 22:58:33 +00:00
Bryan Drewery
7eccb93c02 Explicitly set MAP_PRIVATE to avoid [EINVAL] after r271635.
X-MFC-With:	r271635
Reviewed by:	jhb
2014-09-17 20:26:27 +00:00
John Baldwin
c3d1e48a6b Always seek back to the beginning of a regular directory, even if the
previous seek location was 0.  Without this, readdir() would see
dd_loc of zero and call getdirentries() which would start reading
entries at the current seek location of the directory ignoring the
first batch of entries.  Also, rewinddir() should always seek so that
it reads the directory from the beginning to get updated entries.

PR:		192935
Reported by:	iron@mail.ua
MFC after:	3 days
2014-09-03 19:01:34 +00:00
Sergey Kandaurov
196d2103e6 Fixed ENOMEM description.
MFC after:	1 week
Sponsored by:	Nginx, Inc.
2014-08-13 14:49:51 +00:00
John Baldwin
18ae4fcc47 If telldir() is called immediately after a call to seekdir(), POSIX
requires the return value of telldir() to equal the value passed to
seekdir().  The current seekdir code with SINGLEUSE enabled breaks
this case as each call to telldir() allocates a new cookie.  Instead,
remove the SINGLEUSE code and change telldir() to look for an existing
cookie for the directory's current location rather than always creating
a new cookie.

CR:		https://phabric.freebsd.org/D490
PR:		121656
Reviewed by:	jilles
MFC after:	1 week
2014-07-29 00:16:33 +00:00
John Baldwin
0708297e43 POSIX says that passing a location returned by telldir() to seekdir()
after an intervening call to rewinddir() is undefined, so reclaim any
pending telldir() cookies in the directory when rewinddir() is called.

CR:		D459
Reviewed by:	jilles
MFC after:	1 week
2014-07-24 20:44:30 +00:00
Jilles Tjoelker
becf520163 ttyname(3): Fix EBADF/ENOTTY error descriptions.
Also, make sure to document the return values and errors for all three
functions in the man page.

PR:		191931
MFC after:	1 week
2014-07-18 21:29:59 +00:00
Pedro F. Giffuni
dad64c978f libc/gen: small updates to code originating at OpenBSD
arc4random.c
- CVS rev. 1.22
Change arc4random_uniform() to calculate ``2**32 % upper_bound'' as
``-upper_bound % upper_bound''. Simplifies the code and makes it the
same on both ILP32 and LP64 architectures, and also slightly faster on
LP64 architectures by using a 32-bit remainder instead of a 64-bit
remainder.
- CVS rev. 1.23
Spacing

readpassphrase.c
-CVS rev. v 1.24
most obvious unsigned char casts for ctype

Obtained from:	OpenBSD
MFC after:	5 days
2014-07-15 02:21:35 +00:00
John Baldwin
9f72c0322c Fix some edge cases with rewinddir():
- In the unionfs case, opendir() and fdopendir() read the directory's full
  contents and cache it.  This cache is not refreshed when rewinddir() is
  called, so rewinddir() will not notice updates to a directory.  Fix this
  by splitting the code to fetch a directory's contents out of
  __opendir_common() into a new _filldir() function and call this from
  rewinddir() when operating on a unionfs directory.
- If rewinddir() is called on a directory opened with fdopendir() before
  any directory entries are fetched, rewinddir() will not adjust the seek
  location of the backing file descriptor.  If the file descriptor passed
  to fdopendir() had a non-zero offset, the rewinddir() will not rewind to
  the beginning.  Fix this by always seeking back to 0 in rewinddir().
  This means the dd_rewind hack can also be removed.

While here, add missing locking to rewinddir().

CR:   	    	https://phabric.freebsd.org/D312
Reviewed by:	jilles
MFC after:	1 week
2014-07-11 16:16:26 +00:00
Konstantin Belousov
a028ee5c9f Implement sysconf(_SC_GETGR_R_SIZE_MAX) and sysconf(_SC_GETPW_R_SIZE_MAX).
Reported by:	Dmitry Sivachenko <trtrmitya@gmail.com>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-07-09 19:12:18 +00:00
Marcel Moolenaar
e7d939bda2 Remove ia64.
This includes:
o   All directories named *ia64*
o   All files named *ia64*
o   All ia64-specific code guarded by __ia64__
o   All ia64-specific makefile logic
o   Mention of ia64 in comments and documentation

This excludes:
o   Everything under contrib/
o   Everything under crypto/
o   sys/xen/interface
o   sys/sys/elf_common.h

Discussed at: BSDcan
2014-07-07 00:27:09 +00:00
Baptiste Daroussin
8fbf3d50e3 use .Mt to mark up email addresses consistently (part4)
PR:		191174
Submitted by:	Franco Fichtner  <franco at lastsummer.de>
2014-06-23 08:25:03 +00:00
Sergey Kandaurov
1d8b56e9a0 mdoc: add missing paragraph macro. 2014-05-29 13:35:13 +00:00
Konstantin Belousov
ca5e4fe970 Invalidate the cache for the named posix semaphore when opened and
actual file storing the semaphore object is different from the file
created on the first open.  Store the file st_dev and st_ino members
of the struct stat in the semaphore structure on open, and compare
them with the attributes of the opened file to detect unlink and
re-creation.

This fixes an issue of sem_unlink(3) failing to flush the named entry
in the semaphore list for the current or remote process, making
sem_unlink(3) not correctly operating if the unlinked semaphore is
still opened.

Reported by:	Joris Giovannangeli <joris@giovannangeli.fr>
PR:	standards/189353
Reviewed by:	jilles (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-05-10 19:08:07 +00:00
Konstantin Belousov
9b6224b70f Style.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-05-10 18:59:09 +00:00
Marcel Moolenaar
eef9f6d258 The getlogin_basic() function can return a 0 status with a NULL
pointer for the login name (result). Make sure to handle that
case properly. Improve robustness by checking namelen and then
nul-terminating the provided buffer to simplify subsequent logic.

Obtained from:	Juniper Networks, Inc.
MFC after:	1 week
2014-04-05 18:14:58 +00:00