Add two functions to allow objects that own a file descriptor to
enforce that only they can close their file descriptor.
Use them in FILE* and DIR*.
Bug: http://b/110100358
Test: bionic_unit_tests
Test: aosp/master boots without errors
Test: treehugger
Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
pclose(3) is now an alias for fclose(3). We could add a FORTIFY check
that you use pclose(3) if and only if you used popen(3), but there seems
little value to that when we can just do the right thing.
This patch also adds the missing locking to _fwalk --- we need to lock
both the global list of FILE*s and also each FILE* we touch. POSIX says
that "The popen() function shall ensure that any streams from previous
popen() calls that remain open in the parent process are closed in the
new child process", which we implement via _fwalk(fclose) in the child,
but we might want to just make *all* popen(3) file descriptors O_CLOEXEC
in all cases.
Ignore fewer errors in popen(3) failure cases.
Improve popen(3) test coverage.
Bug: http://b/72470344
Test: ran tests
Change-Id: Ic937594bf28ec88b375f7e5825b9c05f500af438
We've ignored %n for a long time, but that's dangerous too because it
makes it unclear whether the corresponding pointer argument should be
supplied or not.
Remove the ambiguity by just rejecting %n outright.
Bug: http://b/31832608
Test: ran tests
Change-Id: Ic046ad3436a30c6f8f580ea738bdcaeb01c858f8
Based on gaps in the list of functions not referenced by the test
executable.
Bug: N/A
Test: ran tests
Change-Id: I73c238e7cf360f94670c7cd13eb954341c940b7b
Merge CT_CCL and CT_STRING handling before we add %m.
Also fix an accidental scanf/wscanf difference.
Add currently-disabled tests for questionable behavior noticed during
code review that isn't a regression, but should be fixed later.
Bug: http://b/68672236
Bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202240
Test: ran tests
Change-Id: I3eec9b7dfce84f63c68426406224822c52551d64
Strictly, POSIX says "If a '-' is in the scanlist and is not the first
wide character, nor the second where the first wide character is a '^',
nor the last wide character, the behavior is implementation-defined",
but it seems unreasonable for swscanf to interpret `a-c` differently
from sscanf. Make ours behave the same as each other by making swscanf
work the same as sscanf.
Bug: http://b/68672236
Test: ran tests
Change-Id: Ia84805897628d7128e901b468e02504373730e61
Fix the 'j' (intmax_t/uintmax_t) length qualifier in the wide
variant. (With new tests that fail without this fix.)
Fix a typo in the wide support for intmax_t*, which isn't testable because
%n is disabled on Android (and will be removed in a later cleanup pass).
Also move the public vfprintf/vfwprint functions into stdio.cpp.
Bug: http://b/67371539
Test: ran tests
Change-Id: Ib003599b1e9cb789044a068940b59e447f2cb7cb
This patch switches to C++ (in anticipation of needing it later), removes
a little duplication (via a macro for now), and ensures uniform support
for %C/%lc and %S/%ls between regular and wide (with new tests).
Since it's so hard to debug problems in printf (as the time I've wasted
already today will testify), that's all I want to do in this change. The
other 500 lines of diff can wait...
(Also merge "floatio.h" into "local.h" now all the users are in forked
code.)
Bug: http://b/67371539
Test: ran tests
Change-Id: I083353d89c32b9302d759ca6967cc6d8a62cd8a5
Also simplify trivial one-liners like perror/puts/fputs, and clean up
fread/fwrite slightly.
Fix perror to match POSIX.
Add basic perror and *_unlocked tests.
Bug: N/A
Test: ran tests
Change-Id: I63f83c8e0c15c3c4096509d17421ac331b6fc23d
"Although not explicitly required by this volume of POSIX.1-2008, a good
implementation of append (a) mode would cause the O_APPEND flag to be set."
Yeah, about that...
Bug: N/A
Test: ran tests
Change-Id: I23c4bc5c1ebc92e0cb44025d2d313f321f9ffa68
Tag fmemopen_NULL as a known failure, and make it reliably fail by
memsetting the buffer we read to.
Bug: http://b/33251022
Test: bionic-unit-tests/bionic-unit-tests64 on bullhead
Test: bionic-unit-tests-glibc --gtest_filter="*memopen*"
Change-Id: I381783282359851c9de47146dafbb5a291960c2a
The parsefloat routines -- which let us pass NaNs and infinities on to
strto(f|d|ld) -- come from NetBSD.
Also fix LP64's strtold to return a NaN, and fix all the architectures
to return quiet NaNs.
Also fix wcstof/wcstod/wcstold to use parsefloat so they support hex
floats.
Lots of new tests.
Bug: http://b/31101647
Change-Id: Id7d46ac2d8acb8770b5e8c445e87cfabfde6f111
This assumes that it's more likely we're unlinking a file than a directory,
though even if that's not true, as long as a failed unlink(2) is cheaper
than a successful lstat(2) -- which seems likely since there's no data to
copy -- we still win.
Change-Id: I0210e9cd3d31b8cf1813c55c810262ef327382ed
It turns out we don't have any bugs here, but glibc does. Found while
chasing down a toybox failure I saw on the host, but we may as well
add the test in case we ever screw up here in future.
Change-Id: Ib8dd227ed3b742dc4dab8c09dc08e6ea9a35c807
This is a common thing for people to want to do, snprintf requires
a lot of stack for itself, and PTHREAD_STACK_MIN should be usable
for realistic code.
Change-Id: Ib09cfb4e0beec1c69ee0944c3ea4c5d03a94c491
Our fopen/freopen/tmpfile are already always O_LARGEFILE, but let's add
the aliases for _LARGEFILE_SOURCE compatibility.
Bug: http://b/24807045
Change-Id: I5d99b3ef3c9f27ce70f13313f6a92e96c7f21f80
This also lets us test the EOVERFLOW behavior, which pointed out that the
fgetpos/fsetpos return on failure has always been wrong...
Bug: http://b/24807045
Change-Id: I35273eb07c8c9155af858adb27569983397580b6
This test didn't catch anything, but it does ensure that we exercise
the "lots of files" case.
Bug: http://b/26747402
Change-Id: I6c51c6436029572a49190d509f131eb93b808652
BSD doesn't invalidate the fd stored in struct FILE, which can make
it possible (via fileno(3), for example), to perform operations on
an fd you didn't intend to (rather than just failing with EBADF).
Fixing this makes the code slightly simpler anyway, and might help
catch bad code before it ships.
Bug: http://stackoverflow.com/questions/10816837/fclose-works-differently-on-android-and-linux
Change-Id: I9db74584038229499197a2695c70b58ed0372a87
Add a way to turn fortify off for the files that test fortify functions.
This method involves simply compiling the same file with fortify off and
changing the test name slightly.
It's not very pretty, and it assumes that only these few files test
functions that can be fortified.
Bug: 15195631
Change-Id: Iba9db1d508b7d28a1d6968019cb70fe08864827b
Apparently uClibc has a bug here. We don't, but let's keep it that way.
Bug: http://landley.net/notes.html#21-03-2015
Change-Id: If406df963db9bee47921d7a1c116ebcab08d96bf
gcov does writes after reads on the same stream, but the bulk read optimization
was clobbering the FILE _flags, causing fwrite to fail.
Bug: 19129055
Change-Id: I9650cb7de4bb173a706b502406266ed0d2b654d7
Another sizeof/strlen screwup caused by trying to be too clever. Use
std::string instead.
Also fix all the ASSERT_STREQ calls in this file that had the arguments
the right^Wwrong way round. If I ever see Kent Beck...
Change-Id: I47a1bdfee99cf4e7bed9b398f3158a308fbcf1e8
This makes us competitive with glibc for fully-buffered and unbuffered reads,
except in single-threaded situations where glibc avoids locking, but since
we're never really single-threaded anyway, that isn't a priority.
Bug: 18593728
Change-Id: Ib776bfba422ccf46209581fc0dc54f3567645b8f
For tests that call uselocale(), the locale is stored in the
g_userlocale_key thread-specific key. If freelocale() is called later,
then g_uselocal_key points to a deleted pointer. CTS eventually calls
vfprintf to print the result, which calls MB_CUR_MAX and MB_CUR_MAX
accesses the deleted locale stored in g_uselocale_key, causing unpredictable
errors.
Fixed the tests by calling uselocale() with the old locale before
calling freelocale.
(cherry-pick of 8a46cf0fcf82b8c76e05be7e066ec854f974603a.)
Bug: 17299565
Change-Id: I87efa2a9b16999a11d587f68d3aeedcbe6ac8a2c
Previously this was hard coded to 4. This is only the case for UTF-8
locales.
As a side effect, this properly reports C.UTF-8 as the default locale
instead of C.
Change-Id: I7c73cc8fe6ffac61d211cd5f75287e36de06f4fc
These were both removed from POSIX 2004, and we don't define an
implementation for getw(3). Keep the definition of put(3) on LP32 for
binary compatibility.
Bug: 13935372
Change-Id: Iba384b45093ac6d2d7c2d81f7980cd7701dd6f56
The bug here turned out to be that we hadn't increased the constant
corresponding to the maximum number of bytes in a character to match
our new implementation, so any character requiring more than a byte
in UTF-8 would break our printf family.
Bug: 15439554
Change-Id: I693e5e6eb11c640b5886e848502908ec5fff53b1
I've also switched some tests to be positive rather than negative,
because !defined is slightly harder to reason about and there are
only two cases: bionic and glibc.
Change-Id: I8d3ac40420ca5aead3e88c69cf293f267273c8ef
fclose(3) frees the passed-in FILE*. We should close(2) the underlying fd,
not fclose(3) the stream, if we want to test what happens with a stream
we can't read from.
Bug: 14466691
Change-Id: I99fed5904b0266b9c6ae05d0b9cf2e926446c064
printf("%1$s %1$s\n", "test");
would print garbage instead of the second "test". The problem is __find_arguments
and the patch is a backport of two patches from OpenBSD that fix the issue:
Author: tedu <tedu@cvs.openbsd.org>
Date: Sat Apr 29 23:00:24 2006 +0000
check mmap for failure. the helper functions using it return -1, but
callers do not yet check since printf() for example is not documented
to return an error.
some formatting cleanups.
mostly ok deraadt millert
Author: millert <millert@cvs.openbsd.org>
Date: Fri May 16 14:28:54 2008 +0000
C99 says that for each va_copy() there must be a matching va_end().
Replace the non-portable hackery in __find_arguments() with a union.
From FreeBSD.
Change-Id: I6ea392ce6fcf4a319ae6a67ec58cc52fe7cbe534
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
The normal ASSERT_EQ macros don't work quite right for float/double values,
and result in false failures. Use the correct macros instead.
Bug: 13511379
Change-Id: Ic2feee7f3d3569f57b6453b8fa95222846c625cd
In order to be able to generate a list of tests for cts, the same set of
tests must exist across all platforms. This CL adds empty tests where a
test was conditionally compiled out.
This CL creates a single library libBionicTests that includes all of
the tests found in bionic-unit-tests-static.
Also fix a few missing include files in some test files.
Tested by running and compiling the tests for every platform and
verifying the same number of tests are on each platform.
Change-Id: I9989d4bfebb0f9c409a0ce7e87169299eac605a2
It turns out that when passing a closed file to getdelim or getline, the
functions in glibc will properly return a failure, but errno might not be
set. Skip the errno check except on bionic.
Change-Id: I8d625f15303d4c2d42e8d28491ea8a368aea4d32
There is a known bug running clone with the CLONE_VM flag, so for host
create an empty test.
Change the expected output of the stdio test for a glibc difference.
Change the pause test to use ScopedSignalHandler to setup/restore the SIGALRM
handler.
After this, running bionic-unit-tests-glibc passes for all tests.
Bug: 11389824
Change-Id: Ib304eae4164115835a54991dfdca5821ecc3db5e
This fixes a few diverse issues that clang warns on in bionic. First,
it specifies the appropriate converted types for format specifiers.
The "h" and "hh" modifiers specify that the user is passing a short or
char respectively. We were passing int deliberately in both cases and
relying on the compiler to implicitly downcast to the smaller type.
We also remove the non-standard "d" suffix from our double-precision
floating point constant. This is an extension for gcc that clang does
not implement. The third fix is to mark the c1 variable as unused,
since it truly is neither read nor written.
Change-Id: I4793352b9d3e58f1f4cac9e7581ef4b2a70b43c7
Found by adapting the simple unit tests for libc logging to test
snprintf too. Fix taken from upstream OpenBSD without updating
the rest of stdio.
Change-Id: Ie339a8e9393a36080147aae4d6665118e5d93647
This gets us back to using vfork now our ARM vfork assembler stub is
fixed, and adds the missing thread safety for the 'pidlist'.
Bug: 5335385
Change-Id: Ib08bfa65b2cb9fa695717aae629ea14816bf988d
after change 32822 was rejected, this is the more light-weight
version of the fix: libc/include/sys/types.h already - via
libc/kernel/common/linux/posix_types.h - includes a definition
of __kernel_ssize_t from libc/kernel/arch-*/asm/posix_types.h
which is architecture-specific, toolchain-agnostic and also
gets rid of the gcc -Wformat warning (which it issues correctly,
since this i̲s̲ indeed a bug in bionic)
Change-Id: Ie4503ab16628bc25815a836d07556f665e9795c7
MIPS and x86 appear to have been correct already.
(Also fix unit tests that ASSERT_EQ with errno so that the
arguments are in the retarded junit order.)
Bug: 3461078
Change-Id: I2418ea98927b56e15b4ba9cfec97f5e7094c6291
Some userspace programs (e.g. perf) need getline.
Changes:
() add getdelim.c, getline.c from NetBSD (http://netbsd.org/) under the
NetBSD Foundation's (TNF) license ("2 clause" Berkeley-style license).
() add stub for reentrant.h header that is needed by getdelim.c
() add tests for getdelim(3) and getline(3).
() update NOTICE file.
Change-Id: I22ed82dd5904b9d7a3695535c04f502be3c27c5d
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>