Commit Graph

11375 Commits

Author SHA1 Message Date
David Schultz
a2d171e440 Optimize this a bit better.
Submitted by:	bde (although these aren't all of his changes)
2008-01-15 23:31:24 +00:00
John Baldwin
c7716170ef Remove some now-unused macros.
MFC after:	1 week
2008-01-15 18:55:52 +00:00
Tim Kientzle
f432a1c5bc Handle Zip archives that are "multi-part archives with only
one part" by simply ignoring the marker at the beginning
of the file.  (Zip archivers reserve four bytes at the beginning
of each part of a multi-part archive, if it happens to only
require one part, those four bytes get filled with a placeholder
that can be ignored.)

Thanks to: Marius Nuennerich,
	 for pointing me to a Zip archive that libarchive couldn't handle
MFC after: 7 days
2008-01-15 16:27:15 +00:00
John Baldwin
c50897c392 Put back the openpty(3) and ptsname(3) fixes but don't disable ptsname(3)
on pts(4) devices this time.  This fixes the issues while leaving pts(4)
enabled on HEAD.
2008-01-15 15:36:23 +00:00
Colin Percival
d3f576839b Back out last commit, since it accidentally broke pts.
The security fix will be re-committed soon, hopefully without breaking
anything.
2008-01-15 13:59:13 +00:00
David Schultz
00a32d0ca9 In getttyent(3), if /etc/ttys doesn't end in a newline, don't
freak out and keep trying to expand the buffer until realloc()
fails.

PR:	114398
2008-01-15 06:50:50 +00:00
Tim Kientzle
a8f2d755d0 Support uppercase hex digits in cpio archives.
Thanks to: Joshua Kwan
MFC after: 7 days
2008-01-15 04:56:48 +00:00
John Baldwin
16fd04e88e Update the manpage for openpty(3) to account for the recent fixes.
Specifically, remove the BUGS section and note that openpty(3) now always
does the various security-related steps.  Also, update the error return
value section.  The PR below is for the original bug rather than the doc
updates.

MFC after:	1 week
PR:		bin/9770
2008-01-14 23:49:56 +00:00
Colin Percival
160e76972a Fix issues which allow snooping on ptys. [08:01]
Fix an off-by-one error in inet_network(3). [08:02]

Security: FreeBSD-SA-08:01.pty
Security: FreeBSD-SA-08:02.libc
2008-01-14 22:56:05 +00:00
David Schultz
ac48ad2e5e Changing 'r' to a size_t in the previous commit turned quicksort
into slowsort for some sequences because different parts of the
code used 'r' to store two different things, one of which was
signed. Clean things up by splitting 'r' into two variables, and
use a more meaningful name.
2008-01-14 09:21:34 +00:00
David Schultz
d3f9671a7d Implement rintl(), nearbyintl(), lrintl(), and llrintl().
Thanks to bde@ for feedback and testing of rintl().
2008-01-14 02:12:07 +00:00
Tim Kientzle
a0751a90e6 Since the tar bidder can never get called more than once, it
doesn't need to compensate for this situation.

While here, fix a minor longstanding bug that empty tar archives
(which begin with at least 512 zero bytes) never properly reported
their format.  In particular, this fixes the output of:
   bsdtar tvvf /dev/zero

And, of course, a new test to verify that libarchive correctly
recognizes the format of such files.
2008-01-13 23:50:30 +00:00
David E. O'Brien
ef19c627f8 Update for the 'file' 4.23 import. 2008-01-13 20:37:19 +00:00
David Schultz
badf97cd55 Use size_t to avoid overflow when sorting arrays larger than 2 GB.
PR:		111085
MFC after:	2 weeks
2008-01-13 02:11:10 +00:00
Xin LI
8b8ffe64e9 Plug memory leaks that is observed when argbuf or argspc is used in the
context.

Submitted by:	Michal Vranek <michal.vranek seznam cz>
PR:		bin/118380
MFC after:	1 month
2008-01-12 00:54:47 +00:00
David Schultz
73b2958b94 - Correct the range check in the double version to catch negative values
that would overflow.
- Style fixes and improved handling of NaNs suggested by bde.
2008-01-11 04:18:25 +00:00
John Baldwin
ce309a2f26 Add a feature_present(3) function which checks to see if a named kernel
feature is present by checking the kern.features sysctl MIB.

MFC after:	1 week
2008-01-10 22:11:21 +00:00
John Baldwin
8e38aeff17 Add a new file descriptor type for IPC shared memory objects and use it to
implement shm_open(2) and shm_unlink(2) in the kernel:
- Each shared memory file descriptor is associated with a swap-backed vm
  object which provides the backing store.  Each descriptor starts off with
  a size of zero, but the size can be altered via ftruncate(2).  The shared
  memory file descriptors also support fstat(2).  read(2), write(2),
  ioctl(2), select(2), poll(2), and kevent(2) are not supported on shared
  memory file descriptors.
- shm_open(2) and shm_unlink(2) are now implemented as system calls that
  manage shared memory file descriptors.  The virtual namespace that maps
  pathnames to shared memory file descriptors is implemented as a hash
  table where the hash key is generated via the 32-bit Fowler/Noll/Vo hash
  of the pathname.
- As an extension, the constant 'SHM_ANON' may be specified in place of the
  path argument to shm_open(2).  In this case, an unnamed shared memory
  file descriptor will be created similar to the IPC_PRIVATE key for
  shmget(2).  Note that the shared memory object can still be shared among
  processes by sharing the file descriptor via fork(2) or sendmsg(2), but
  it is unnamed.  This effectively serves to implement the getmemfd() idea
  bandied about the lists several times over the years.
- The backing store for shared memory file descriptors are garbage
  collected when they are not referenced by any open file descriptors or
  the shm_open(2) virtual namespace.

Submitted by:	dillon, peter (previous versions)
Submitted by:	rwatson (I based this on his version)
Reviewed by:	alc (suggested converting getmemfd() to shm_open())
2008-01-08 21:58:16 +00:00
David Xu
0c921dadbb sem_post() requires to return -1 on error. 2008-01-07 02:26:29 +00:00
Jason Evans
f38512f4af Enable both sbrk(2)- and mmap(2)-based memory acquisition methods by
default.  This has the disadvantage of rendering the datasize resource
limit irrelevant, but without this change, legitimate uses of more
memory than will fit in the data segment are thwarted by default.

Fix chunk_alloc_mmap() to work correctly if initial mapping is not
chunk-aligned and mapping extension fails.
2008-01-03 23:22:13 +00:00
Dag-Erling Smørgrav
aa1b83ec5a Crib {be,le}{16,32,64}{dec,enc} from src/sys/sys/endian.h and use it instead
of home-rolled [iu][248] in the ZIP support code.

Approved by:	kientzle
2008-01-03 18:30:37 +00:00
Dag-Erling Smørgrav
4823b3de93 Add an internal utility function to simplify the many, many places where
the number of bytes read is actually not important as long as we have at
least what we ask for.  Illustrate its benefits by using it throughout
the ZIP support code, except for the few cases where it doesn't apply.

Approved by:	kientzle
2008-01-03 17:54:26 +00:00
Tim Kientzle
2a5e8d812c Extensive improvements to the libarchive_test test program that
exercises and verifies the libarchive APIs:

* Improved error reporting; hexdumps are now provided for
  many file/memory content differences.
* Overall status more clearly counts "tests" and "assertions"
* Reference files can now be stored on disk instead of having
  to be compiled into the test program itself.  A couple of
  tests have been converted to this more natural structure.
* Several memory leaks corrected so that leaks within libarchive
  itself can be more easily detected and diagnosed.
* New test: GNU tar compatibility
* New test: Zip compatibility
* New test: Zero-byte writes to a compressed archive entry
* New test: archive_entry_strmode() format verification
* New test: mtree reader
* New test: write/read of large (2G - 1TB) entries to tar archives
  (thanks to recent performance work, this test only requires a few seconds)
* New test: detailed format verification of cpio odc and newc writers
* Many minor additions/improvements to existing tests as well.
2008-01-01 22:28:04 +00:00
Tim Kientzle
db267e0b5d The mtree.5 file has been moved to src/usr.sbin/mtree. 2008-01-01 06:17:05 +00:00
Jason Evans
36ac4cc502 Fix a major chunk-related memory leak in chunk_dealloc_dss_record(). [1]
Clean up DSS-related locking and protect all pertinent variables with
dss_mtx (remove dss_chunks_mtx).  This fixes race conditions that could
cause chunk leaks.

Reported by:	[1] kris
2007-12-31 06:19:48 +00:00
Jason Evans
07aa172f11 Fix a bug related to sbrk() calls that could cause address space leaks.
This is a long-standing bug, but until recent changes it was difficult
to trigger, and even then its impact was non-catastrophic, with the
exception of revision 1.157.

Optimize chunk_alloc_mmap() to avoid the need for unmapping pages in the
common case.  Thanks go to Kris Kennaway for a patch that inspired this
change.

Do not maintain a record of previously mmap'ed chunk address ranges.
The original intent was to avoid the extra system call overhead in
chunk_alloc_mmap(), which is no longer a concern.  This also allows some
simplifications for the tree of unused DSS chunks.

Introduce huge_mtx and dss_chunks_mtx to replace chunks_mtx.  There was
no compelling reason to use the same mutex for these disjoint purposes.

Avoid memset() for huge allocations when possible.

Maintain two trees instead of one for tracking unused DSS address
ranges.  This allows scalable allocation of multi-chunk huge objects in
the DSS.  Previously, multi-chunk huge allocation requests failed if the
DSS could not be extended.
2007-12-31 00:59:16 +00:00
Rong-En Fan
862f33ce5a - Update build glue for 5.6-20071222 2007-12-30 11:17:40 +00:00
Tim Kientzle
9dd49f960f Update libarchive to 2.4.10. This includes a number of improvements
that I've been working on but put off committing until after the
RELENG_7 branch, including:

* New manpages: cpio.5 mtree.5
* New archive_entry_strmode()
* New archive_entry_link_resolver()
* New read support: mtree format
* Internal API change:  read format auction only runs once
* Running the auction only once allowed simplifying a lot of bid logic.
* Cpio robustness:  search for next header after a sync error
* Support device nodes on ISO9660 images
* Eliminate a lot of unnecessary copies for uncompressed archives
* Corrected handling of new GNU --sparse --posix formats
* Correctly handle a zero-byte write to a compressed archive
* Fixed memory leaks

Many of these improvements were motivated by the upcoming bsdcpio
front-end.

There have also been extensive improvements to the libarchive_test
test harness, which I'll commit separately.
2007-12-30 04:58:22 +00:00
Jeff Roberson
5c556b8aee - Update kvm_deadfiles to be compatible with the new system which has no
global list of all files.
 - Mark kvm_getfiles() as broken since the live version exports struct xfile
   with no filelist at the head and does so incorrectly and the deadfiles
   version exports struct file with a filelist at the head.  It is not known
   if either version works or complies to the manpage.
2007-12-30 01:43:51 +00:00
Jason Evans
14a7e7b5e1 Back out premature commit of previous version. 2007-12-28 09:21:12 +00:00
Jason Evans
03947063d0 Maintain two trees instead of one (old_chunks --> old_chunks_{ad,szad}) in
order to support re-use of multi-chunk unused regions within the DSS for
huge allocations.  This generalization is important to correct function
when mmap-based allocation is disabled.

Avoid zeroing re-used memory in the DSS unless it really needs to be
zeroed.
2007-12-28 07:24:19 +00:00
Jason Evans
3762647250 Release chunks_mtx for all paths through chunk_dealloc().
Reported by:	kris
2007-12-28 02:15:08 +00:00
Jason Evans
ebc87e7e0b Add the 'D' and 'M' run time options, and use them to control whether
memory is acquired from the system via sbrk(2) and/or mmap(2).  By default,
use sbrk(2) only, in order to support traditional use of resource limits.
Additionally, when both options are enabled, prefer the data segment to
anonymous mappings, in order to coexist better with large file mappings
in applications on 32-bit platforms.  This change has the potential to
increase memory fragmentation due to the linear nature of the data
segment, but from a performance perspective this is mitigated by the use
of madvise(2). [1]

Add the ability to interpret integer prefixes in MALLOC_OPTIONS
processing.  For example, MALLOC_OPTIONS=lllllllll can now be specified as
MALLOC_OPTIONS=9l.

Reported by:	[1] rwatson
Design review:	[1] alc, peter, rwatson
2007-12-27 23:29:44 +00:00
John Baldwin
6457bae568 Fix a typo in regards to the ENOENT error.
PR:		docs/118929
Submitted by:	mymtom of hotmail
MFC after:	3 days
2007-12-27 21:55:49 +00:00
John Baldwin
d32324f64f Clean up some of the pts(4) vs pty(4) stuff in grantpt(3) and friends:
- Use PTY* for all pty(4) related constants.
- Use PTMX* for all pts(4) related constants.
- Consistently use _PATH_DEV PTMX rather than "/dev/ptmx".
- Revert 1.7 and properly fix it by using the correct prefix string for
  pts(4) masters.

MFC after:	3 days
2007-12-21 21:26:08 +00:00
Dag-Erling Smørgrav
64dbe1a7af Adjust for OpenPAM Hydrangea. 2007-12-21 12:00:16 +00:00
John Baldwin
889befc455 Invoke revoke(2) on the slave pty in the pts(4) case (new_openpty()) to
kick off any other users on the device line before using it since
openpty(3) is documented to do this.  Note that grantpt(3) does not
call revoke(2), it only adjusts permissions and ownership.

MFC after:	3 days
2007-12-20 21:10:06 +00:00
David Xu
9ba01c866b call underscore version of pthread_cleanup_pop instead. 2007-12-20 04:40:12 +00:00
David Xu
06c8eb55ce Remove vfork() overloading, it is no longer needed. 2007-12-20 04:32:28 +00:00
David Schultz
45310fdb5d Grumble. DO declare logbl(), DON'T declare logl() just yet.
bde is going to commit logl() Real Soon Now.
I'm just trying to slow him down with merge conflicts.

Noticed by:	bde
2007-12-20 03:16:55 +00:00
David Schultz
58c9a67ed7 Remove the declaration of logl(). The relevant bits haven't been
committed yet, but the declaration leaked in when I added nan() and
friends.

Reported by:	pav
2007-12-20 00:06:33 +00:00
Ruslan Ermilov
edabafcb01 Add missing dependencies on Makefile (fixes NO_CLEAN builds). 2007-12-19 05:10:07 +00:00
Warner Losh
9227047ec5 Reduce lock contention for simple cases.
# this really should be done with pthread_once, but I've debugged this code.

Reviewed by: arch@
2007-12-19 04:30:10 +00:00
Warner Losh
19166a3998 Add note about other systems. 2007-12-19 03:33:13 +00:00
Dag-Erling Smørgrav
facd982794 As several people pointed out, I did all the ctype casts the wrong
way (not for the first time...)

Noticed by:	bde, ru ++
MFC after:	1 week
2007-12-19 00:26:36 +00:00
David Schultz
7ff4930d73 Move all the xprintf-related symbols to FBSDprivate_1.0.
Discussed with:	deischen, kan, phk
2007-12-18 23:49:05 +00:00
David Schultz
7cd4a83267 Since nan() is supposed to work the same as strtod("nan(...)", NULL),
my original implementation made both use the same code. Unfortunately,
this meant libm depended on a vendor header at compile time and previously-
unexposed vendor bits in libc at runtime.

Hence, I just wrote my own version of the relevant vendor routine. As it
turns out, mine has a factor of 8 fewer of lines of code, and is a bit more
readable anyway. The strtod() and *scanf() routines still use vendor code.

Reviewed by:	bde
2007-12-18 23:46:32 +00:00
Dag-Erling Smørgrav
e99ace3508 Document NO_PROXY / no_proxy.
MFC after:	3 weeks
2007-12-18 11:03:26 +00:00
Dag-Erling Smørgrav
62a2681c93 Add support for the NO_PROXY / no_proxy environment variable as used by
lynx, curl etc.  Note that this patch differs significantly from that
in the PR, as the submitter refined it after submitting the PR.

PR:		110388
Submitted by:	Alexander Pohoyda <alexander.pohoyda@gmx.net>
MFC after:	3 weeks
2007-12-18 11:03:07 +00:00
Dag-Erling Smørgrav
836e34eeae Old patch I had lying around: correctly cast the argument to is*().
IWBNI gcc could warn about this the way it warns about printf() abuse.

MFC after:	1 week
2007-12-18 10:41:12 +00:00