Commit Graph

61 Commits

Author SHA1 Message Date
Xin LI
4188ba1a3b Fix race condition in catopen(3).
The current code uses a rwlock to protect the cached list, which
in turn holds a list of catentry objects, and increments reference
count while holding only read lock.

Fix this by converting the reference counter to use atomic operations.

While I'm there, also perform some clean ups around memory operations.

PR:		202636
Reported by:	Henry Hu <henry.hu.sh@gmail.com>
Reviewed by:	markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D24095
2020-03-19 06:33:06 +00:00
Andrey A. Chernov
95f9709424 Use current locale (f.e. set by thread). It was global locale always
previously.

MFC after:      7 days
2016-08-24 16:44:27 +00:00
Bryan Drewery
b231dc0a9f Move logic to destroy a struct catentry to its own function.
This will be used later for memory leak handling.

Obtained from:	OneFS
Sponsored by:	EMC / Isilon Storage Division
2016-02-02 23:33:58 +00:00
Bryan Drewery
1bb3a25f07 When catopen(3) returns an error, it caches the result of that error
from r202992. The refcount on the cache entry is not initialized, so
any attempt to clean the cache will skip over this item since it likely
has a >0 value.

This change is currently a NOP. There is work in progress to support
freeing the cache which requires this change to avoid a memory leak.

MFC after:	2 weeks
Sponsored by:	EMC / Isilon Storage Division
2015-02-10 20:45:40 +00:00
Eitan Adler
49a8f2aa6c Fix warning from valgrind when a failed entry is tested.
PR:		kern/173008
Submitted by:	Zhihao Yuan <lichray@gmail.com>
Reviewed by:	gabor
Approved by:	cperciva (implicit)
MFC after:	1 week
2012-12-17 12:57:36 +00:00
Jilles Tjoelker
05eb11cbc4 libc: Use O_CLOEXEC for various internal file descriptors.
This fixes a race condition where another thread may fork() before CLOEXEC
is set, unintentionally passing the descriptor to the child process.

This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still
leaves a race window so it should be fixed later.
2012-09-29 11:54:34 +00:00
Gabor Kovesdan
29c271590e - More style(9) fixups
Approved by:	delphij (mentor)
2010-02-20 08:19:19 +00:00
Gabor Kovesdan
fe0aca73ed - Deal with some special cases [1]
- style(9) nits

Pointed out by:	jilles [1]
Approved by:	delphij (mentor)
2010-02-09 19:37:12 +00:00
Gabor Kovesdan
336831f034 - Fix some style(9) bugs
Pointed out by:	bde
2010-01-29 18:33:59 +00:00
Gabor Kovesdan
fe1ee31bc8 - style(9)
Approved by:	delphij
2010-01-25 23:44:00 +00:00
Gabor Kovesdan
f978ef9381 Cache failing and opened catalogs in catopen() and related functions.
Continuous catopen() calls cause 4 failig stat(2) each, which means a lot
of overhead.  It is also a good idea to keep the opened catalogs in the memory
to speed up further catopen() calls to the same catalog since these catalogs
are not big at all.  In this case, we count references and only free() the
allocated space when the reference count reaches 0.  The reads and writes to
the cache are syncronized with an rwlock when these functions are called from
a threaded program.

Requested by:	kib
Approved by:	delphij
2010-01-25 23:37:49 +00:00
Alexey Zelkin
fd5cf7c013 Bring in NetBSD's improvements and cleanups to NLS subsystem, making
it type and endian clean and removing of stdio dependency from NLS
functions (catalog files now are processed via mmap())

Also following changes were done (against NetBSD version):

. If mmap() failed, set errno to EINVAL and do not try to munmap() file

Obtained from:	NetBSD
2005-02-27 16:26:49 +00:00
Alexey Zelkin
f24d446afb Cleanup prototypes and remove dead code
MFC After:      3 days
2005-02-01 16:04:55 +00:00
Tim J. Robbins
4539e95a0f Remove incomplete support for running FreeBSD userland on old NetBSD kernels
lacking the issetugid() and utrace() syscalls.
2003-10-29 10:45:01 +00:00
Jacques Vidrine
d05090827f Back out the `hiding' of strlcpy and strlcat. Several people
vocally objected to this safety belt.
2003-05-01 19:03:14 +00:00
Jacques Vidrine
5723e501ab `Hide' strlcpy and strlcat (using the namespace.h / __weak_reference
technique) so that we don't wind up calling into an application's
version if the application defines them.

Inspired by:	qpopper's interfering and buggy version of strlcpy
2003-04-29 21:13:50 +00:00
Garrett Wollman
688dfe4533 Do not include <sys/syslimits.h> directly; it is not intended for general
consumption.
2002-10-27 17:44:33 +00:00
Andrey A. Chernov
7e3c1a3cb7 Now, malloc is fixed, remove ENOMEM hardcode 2002-08-12 11:47:19 +00:00
Andrey A. Chernov
315009a483 Set errno to ENOMEM for strdup too (due to malloc errno bug) 2002-08-07 23:52:28 +00:00
Andrey A. Chernov
cb9772d882 Always set errno to ENOMEM after malloc failed (as workaround).
Our malloc sometimes forget to set errno, f.e. for size overflow case.
2002-08-07 22:03:46 +00:00
Andrey A. Chernov
dfb18183be Close descriptor, if error happens in loadCat() 2002-08-07 07:02:37 +00:00
Andrey A. Chernov
97c54f7797 Try harder to check lang as path component (".", "..", / inside).
Try harder to not overwrite failure errno.
style(9) whitespace reformatting for code readability.
2002-08-04 14:03:59 +00:00
David E. O'Brien
333fc21e3c Fix the style of the SCM ID's.
I believe have made all of libc .c's as consistent as possible.
2002-03-22 21:53:29 +00:00
Ruslan Ermilov
8af1452cf8 Removed duplicate VCS ID tags, as per style(9). 2001-08-13 14:06:34 +00:00
Daniel Eischen
d201fe46e3 Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions.  If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
	__sys_foo - actual system call
	_foo - weak definition to __sys_foo
	foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo.  In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde).  All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes.  <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h  namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE.  We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by:	-arch
2001-01-24 13:01:12 +00:00
Alexey Zelkin
e3950d8e0e Fix typo
PR:		misc/21596
Submitted by:	TOGAWA Satoshi <toga@puyo.org>
2000-09-27 18:24:31 +00:00
Andrey A. Chernov
86797bf956 Prevent buffer overflow if NLSPATH is too long 2000-09-08 11:42:37 +00:00
Andrey A. Chernov
f3ed913592 Fully implement NLSPATH processing as described in SUSv2 2000-09-05 14:04:21 +00:00
Alexey Zelkin
316321ebdf Oops! don't set errno to ENOMEM explicitly if malloc() failed.
Found by:	ache
2000-09-05 12:23:08 +00:00
Alexey Zelkin
49b8dd0db5 Finaly cleanup libc/nls code:
* rewrite catopen() to remove duplicate code chunks and optimize
* if empty string is passed to catopen() as name argument then
   catopen() will set errno to ENOENT (File not found), not EINVAL
* move search code to LOOKUP() macro to shrink amount of duplicated code
* move common resource freeing actions to __nls_free_resources() function
* exclude from build code related to MCLoadAll defintion since it is not
  using at all
* style(9) related whitespace changes

Reviewed by:	ache
2000-09-04 12:09:40 +00:00
Andrey A. Chernov
08ba69b8a4 Rewrite using stdio. It cause program speedup since eliminates lots of small
read() syscalls.  It not cause static binary size increasing because stdio
already picked via setlocale() called from catopen()
2000-09-03 21:05:10 +00:00
Andrey A. Chernov
56338d5acb Treat empty lang as "C" lang too 2000-09-01 13:19:18 +00:00
Alexey Zelkin
a8a87cc61b Set rcsid to correct value
Resort #include files
Remove SYSV compatibility chunks
2000-09-01 12:19:00 +00:00
Alexey Zelkin
6b9175e062 Remove unused indirect references to cat* functions. 2000-09-01 12:10:59 +00:00
Alexey Zelkin
a367b9700f Fix memory leak introduced by kris in rev 1.22 2000-09-01 11:56:31 +00:00
Andrey A. Chernov
460b926285 setlocale may return NULL, handle this case too by resetting to "C" 2000-09-01 11:13:38 +00:00
Andrey A. Chernov
016de69d9e Move protection code down to handle NL_CAT_LOCALE case too. 2000-09-01 11:09:34 +00:00
Andrey A. Chernov
53d620a5fb Protect from badly formed LANG variable 2000-09-01 10:54:04 +00:00
Andrey A. Chernov
b9b68e50dc catgets: detect if fd becomes invalid after exec and return default response
cosmetique, use NULL for pointers comparison
2000-08-30 11:44:44 +00:00
Kris Kennaway
84b578d562 Prevent internal buffer overflow due to expansion of $LANG and/or name
argument in catopen().

Reviewed by:	chris, -audit
2000-08-05 04:56:43 +00:00
Jason Evans
9233c4d942 Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo().  In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate.  In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by:	deischen
2000-01-27 23:07:25 +00:00
Jason Evans
929273386f Add three-tier symbol naming in support of POSIX thread cancellation
points.  For library functions, the pattern is __sleep() <--
_libc_sleep() <-- sleep().  The arrows represent weak aliases.  For
system calls, the pattern is _read() <-- _libc_read() <-- read().
2000-01-12 09:23:48 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Andrey A. Chernov
dfb1b7aea6 Provide meaningful errno value on error return 1998-07-14 18:27:43 +00:00
Andrey A. Chernov
e3b0c2a695 Return -1 for invalid descriptor in catclose 1998-04-30 13:15:31 +00:00
Andrey A. Chernov
e97ef24c18 If passed catgets descriptor is NULL or -1, return default string immediately 1998-04-30 12:25:05 +00:00
Andrey A. Chernov
9ad256ad65 Force loadType to 0 1998-04-30 11:39:08 +00:00
Andrey A. Chernov
c897062234 Implement NL_CAT_LOCALE
Manpages cleanup
1998-04-30 11:06:12 +00:00
Andrey A. Chernov
1adba262d7 Prototypes/typedefs cleanup
Fix error return codes
1998-04-30 10:14:55 +00:00
John Birrell
c61e516832 Add #ifndef __NETBSD_SYSCALLS around calls to issetugid() which
do not exist in NetBSD 1.3.
1998-01-15 09:58:08 +00:00