Commit Graph

50 Commits

Author SHA1 Message Date
Eric van Gyzen
079171874c iconvctl(3): remove superfluous NULL pointer tests
convname and dst are guaranteed to be non-NULL by iconv_open(3).
src is an array. Remove these tests for NULL pointers.
While I'm here, eliminate a strlcpy with a correct but suspicious-looking
calculation for the third parameter (i.e. not a simple sizeof).
Compare the strings in-place instead of copying.

Found by:	bdrewery
Found by:	Coverity
CID:		1130050, 1130056
MFC after:	3 days
Sponsored by:	Dell Inc.
Differential Revision:	 https://reviews.freebsd.org/D6338
2016-05-14 00:35:35 +00:00
Pedro F. Giffuni
32223c1b7d libc: spelling fixes.
Mostly on comments.
2016-04-30 01:24:24 +00:00
Ed Maste
c38dac681d libc: don't build compat functions if building WITHOUT_SYMVER
WITHOUT_SYMVER necessarily implies building a system without symver
backwards compatability.

Sponsored by:	The FreeBSD Foundation
2016-03-15 19:26:32 +00:00
Jilles Tjoelker
59797edfd8 libc: Use namespace.h in a few more files.
libc now no longer calls fstat(), socketpair() and wait(), only the
underscore-prefixed versions (_waitpid() instead of wait()).
2015-12-20 23:05:20 +00:00
Bryan Drewery
277a765cf4 Use memmove(3) to avoid overlapping copy.
Reported by:	valgrind
MFC after:	2 weeks
X-MFC-With:	r290168
2015-10-29 23:06:33 +00:00
Bryan Drewery
d8a7885b36 Fix several memory leaks, and crashes, in iconvlist(3).
- Both curitem and curitem (via the names list) was always leaked.
- malloc(3) failures lead to some leaks.
- __bsd___iconv_get_list() failure lead to a crash since its error was not
  handles and __bsd___iconv_free_list() is not NULL-safe.

I have slightly refactored this to avoid extra malloc and free logic in cases
of malloc(3) failing.

There are still bad assumptions here that I did not deal with.  One of which is
that the data will always have a '/' so the strchr(3) will not return NULL.

Coverity CID:	1130055 1130054 1130053
2015-10-29 23:02:34 +00:00
Pedro F. Giffuni
4194e4e371 Fix improbable memory leak in _citrus_prop_read_str().
Found by:	Clang Static Analyzer
2015-04-20 22:09:50 +00:00
Tijl Coosemans
1243a98e38 Remove the const qualifier from iconv(3) to comply with POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/iconv.html

Adjust all code that calls iconv.

PR:		199099
Exp-run by:	antoine
MFC after:	2 weeks
2015-04-15 09:09:20 +00:00
Alexander Kabaev
3956b1013e Avoid lookup of CODESET aliases using uninitialized path
We do not use iconv.alias file, so avoid using the vestiges
of the code that do.

Differential Revision:	https://reviews.freebsd.org/D1729
Reviewed by: emaste
MFC after: 2 weeks
2015-02-28 20:30:25 +00:00
Joel Dahl
f636caf195 mdoc: paragraph improvements. 2015-01-04 12:49:24 +00:00
Joel Dahl
4990a1c050 mdoc: improvements to SEE ALSO. 2014-12-27 08:31:52 +00:00
Jun Kuriyama
d38b156d2e Fix incorrect type of "invalids" argument in __iconv() prototype. 2014-12-15 14:36:04 +00:00
John-Mark Gurney
8029eb754a fix misordering...
Obtained from:	gjb
MFC after:	1 week
2014-08-04 21:12:38 +00:00
John-Mark Gurney
9c0b8e489d add xrefs for the other functions...
There should be more text in this page talking about each of these links,
but at least people know about them now...

MFC after:	1 week
2014-08-04 20:58:59 +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
Tijl Coosemans
cdd0ebc93b iconv_open: initialise ci_ilseq_invalid field of _citrus_iconv_shared
struct after allocation with malloc.

iconvlist: reduce a memory leak by copying strings only once.
2014-06-13 08:36:10 +00:00
Tijl Coosemans
3fc3c30a27 Replace malloc+memset with calloc. 2014-06-13 08:28:51 +00:00
Tijl Coosemans
9ca40936af - In the libiconv module for ISO 2022 restore the original order of the
fields of a private struct such that variables of this type are
  initialised correctly.  Fixes conversion from ISO 2022.
  Also do this in the BIG5 module to prevent similar errors in the future.
- In the libiconv module for EUC-TW replace 2^cs with 1<<cs.  Fixes
  conversion from EUC-TW.
- Synchronise iconv code with NetBSD.  In most cases this only updates
  the RCS id because the changes are already there or are NetBSD specific.
  + libc/iconv/citrus_csmapper.c: Add a comment.
  + libc/iconv/citrus_db_factory.c: Remove put16().
  + libc/iconv/citrus_iconv.c: Return EINVAL on error.
  + libc/iconv/citrus_mapper.c: Return EINVAL on error.
  + libc/iconv/citrus_memstream.c: Fix type of a variable.
  + libc/iconv/citrus_prop.h: Sync definition of _CITRUS_PROP_HINT_END.
  + libc/iconv/citrus_stdenc.c: Return EINVAL on error.
  + libiconv_modules/mapper_std/citrus_mapper_std.c: Plug memory leak.

Obtained from:	NetBSD
MFC after:	2 weeks
2014-04-01 10:36:11 +00:00
Marcel Moolenaar
8876613dc5 Replace use of ${.CURDIR} by ${LIBC_SRCTOP} and define ${LIBC_SRCTOP}
if not already defined. This allows building libc from outside of
lib/libc using a reach-over makefile.

A typical use-case is to build a standard ILP32 version and a COMPAT32
version in a single iteration by building the COMPAT32 version using a
reach-over makefile.

Obtained from:	Juniper Networks, Inc.
2014-03-04 02:19:39 +00:00
Tijl Coosemans
64f204f9dd Consistently pass around context information using a simple pointer. This
fixes some dereferencing bugs in Chinese character set conversions.

PR:		185964
MFC after:	5 days
2014-02-24 13:33:20 +00:00
Ulrich Spörlein
d7d8b00bec mdoc: fix several uses of the Fx macro to point to actual releases.
Found by:  make manlint
2014-01-28 21:40:10 +00:00
Peter Wemm
db2af39373 Move the iconv wrapper source from libc_nonshared to libc/iconv so that
it is all in the one place again.  Rename libc/iconv/iconv.c to
bsd_iconv.c. Compile the wrappers into libc.a so that WITHOUT_DYNAMICROOT
works again.

Discussed with:	kib (and partly stolen from his patch)
2013-11-25 20:17:55 +00:00
Hiroki Sato
7c5b23111c Add ICONV_{GET,SET}_ILSEQ_INVALID iconvctl. GNU iconv returns EILSEQ
when there is an invalid character in the output codeset while it is
valid in the input.  However, POSIX requires iconv() to perform an
implementation-defined conversion on the character.  So, Citrus iconv converts
such a character to a special character which means it is invalid in the
output codeset.

This is not a problem in most cases but some software like libxml2 depends
on GNU's behavior to determine if a character is output as-is or another form
such as a character entity (&#NNN;).
2013-11-25 01:26:06 +00:00
Peter Wemm
091b8336ae Attempt to move the POSIX iconv* symbols out of runtime linker space.
FreeBSD systems usually implemented this as a third party module and
our implementation hasn't played as nicely with the old way as it could
have.

To that end:
* Rename the iconv* symbols in libc.so.7 to have a __bsd_ prefix.
* Provide .symver compatability with existing 10.x+ binaries that
  referenced the iconv symbols. All existing binaries should work.
* Like on Linux/glibc systems, add a libc_nonshared.a to the ldscript
  at /usr/lib/libc.so.
* Move the "iconv*" wrapper symbols to libc_nonshared.a

This should solve the runtime ambiguity about which symbols resolve
to where.  If you compile against the iconv in libc, your runtime
dependencies will be unambiguous.

Old 9.x libraries and binaries will always resolve against their
libiconv.so.3 like they did on 9.x.  They won't resolve against libc.

Old 10.x binaries will be satisified by the .symver helpers.

This should allow ports to selectively compile against the libiconv
port if needed and it should behave without ambiguity now.

Discussed with:	 kib
2013-11-17 22:52:17 +00:00
Dimitry Andric
1c5ce94f1d Fix typo in include guard, found by clang 3.4.
MFC after:	3 days
2013-11-08 17:23:37 +00:00
Peter Wemm
912ce912e1 Remove the WITH_LIBICONV_COMPAT hack that seems to do more harm than
good.  This caused libc to spoof the ports libiconv namespace and
provide a colliding libiconv.so.3 to fool rtld.  This should have
been removed some time ago.
2013-11-03 19:04:57 +00:00
Xin LI
5e9a119cd6 Drop cm_lock before calling mapper_close, which in turn could call
_citrus_mapper_close again and result in a deadlock otherwise.

This is similar to NetBSD PR/24023 (fixed in their r1.5 of this file).

PR:		bin/182994
Submitted by:	Fabian Keil <fk fabiankeil de>
MFC after:	3 days
2013-10-21 07:58:37 +00:00
David Chisnall
b49c0d5878 Fix the namespace pollution caused by iconv.h including stdbool.h
This broke any C89 ports that defined bool themselves, including things
like gcc, gtk, and so on.
2013-09-06 09:46:44 +00:00
Peter Wemm
60c412bb16 Expose _citrus_bcs_trunc_rws_len for libintl's use.
Submitted by:	Jan Beich <jbeich@tormail.org>
2013-08-13 18:14:53 +00:00
Peter Wemm
0ff204bbd1 The iconv in libc did two things - implement the standard APIs, the GNU
extensions and also tried to be link time compatible with ports libiconv.
This splits that functionality and enables the parts that shouldn't
interfere with the port by default.

WITH_ICONV (now on by default) - adds iconv.h, iconv_open(3) etc.
WITH_LIBICONV_COMPAT (off by default) adds the libiconv_open etc API, linker
symbols and even a stub libiconv.so.3 that are good enough to be able
to 'pkg delete -f libiconv' on a running system and reasonably expect it
to work.

I have tortured many machines over the last few days to try and reduce
the possibilities of foot-shooting as much as I can.  I've successfully
recompiled to enable and disable the libiconv_compat modes, ports that use
libiconv alongside system iconv etc.  If you don't enable the
WITH_LIBICONV_COMPAT switch, they don't share symbol space.

This is an extension of behavior on other system.  iconv(3) is a standard
libc interface and libiconv port expects to be able to run alongside it on
systems that have it.

Bumped osreldate.
2013-08-13 07:15:01 +00:00
Peter Wemm
f9562c1748 Our libc iconv (unlike gnu iconv and the citrus code in NetBSD) has a
bypass mode when src == dst.  Unfortunately, there are tools in ports
that pass byte streams through iconv to determine if the encodings
are valid.  eg: gettext-0.18.3+.

Disable the optimization and behave like the other implementations.
2013-08-08 01:53:27 +00:00
Peter Wemm
ff0b75b897 Make it clear that there are three separate internal locks. 2013-07-03 18:35:21 +00:00
Peter Wemm
7900abff04 As a followup to r252547, propate const down the call stack. 2013-07-03 18:27:45 +00:00
Peter Wemm
19dfd82d81 Replace the #define for "iconv" so it is for the function name instead of
a macro with parameters.  Remove a __DECONST hack and add consts instead
for gnu libiconv API compatability.  This makes it work with things like
devel/boost-libs that expects to use "iconv" as though it were a pointer.
2013-07-03 07:03:19 +00:00
Peter Wemm
7c5cb6be8c If strdup failed, don't try and free the wrong thing. 2013-07-01 08:38:31 +00:00
Peter Wemm
3d4b80da4e __weak_alias() doesn't exist on FreeBSD. Use __weak_reference();
Expose iconv functions as weak symbols as well as their internal
remapped #define names.  This is necessary for autoconf compatability -
on Linux it appears that #include <iconv.h> isn't a link time
prerequisite for their version that's built into glibc.

Initialize the pthread rwlock.  Note that upstream has three
separate locks.  The file-local static lock appears intentional.

I'm using this as a ports-compatible compile-time substitute for
converters/libiconv on one of my personal machines.
2013-07-01 08:06:26 +00:00
Ed Schouten
a6f45121b5 Make some tiny improvements to iconv_open().
- Remove an unneeded variable.
- Fix whitespace bugs.
- Fix typoes in comment.
- Improve string handling a bit. Don't handroll strstr() and don't
  terminate a strdup()'ed string. Instead, simply strndup() the part we
  need.
2013-05-25 12:13:54 +00:00
Ed Schouten
907b803190 Only call free() on something we allocated.
If we were already provided a struct _citrus_iconv (e.g. through
iconv_open_into()), we should not call free() in case io_init_context()
fails. Instead, call it on the pointer of the allocated object, which
will be NULL in case of iconv_open_into().
2013-05-25 12:11:20 +00:00
Ed Schouten
b94c7c3e21 Let iconv build on -HEAD properly.
- Add NO_WMISSING_VARIABLE_DECLARATIONS where we use Yacc/Lex.
- Add variable declarations where possible.
- Add missing static keyword.
2013-05-23 18:07:01 +00:00
Jilles Tjoelker
571d9493ad libc/iconv: Fix race condition with setting FD_CLOEXEC.
A fork/exec could happen between open and fcntl, leaking a file descriptor.
Using O_CLOEXEC fixes this and as a side effect simplifies the code.

NetBSD already had this (I checked this after making the change myself).

Reviewed by:	gabor
2012-12-17 10:38:51 +00:00
Joel Dahl
3b3faeb9da Fix Fo arguments.
Reviewed by:	gabor
2012-03-28 19:20:28 +00:00
Joel Dahl
539617ec61 mdoc: add missing El macro. 2012-03-27 20:50:14 +00:00
Joel Dahl
46355096e1 mdoc: correct .Bd/.Bl arguments.
Reviewed by:	brueffer
2012-03-26 21:22:53 +00:00
Joel Dahl
7226ab98cf Fix date. 2012-03-26 14:56:23 +00:00
Colin Percival
3e65b9c6e6 Fix a problem whereby a corrupt DNS record can cause named to crash. [11:06]
Add an API for alerting internal libc routines to the presence of
"unsafe" paths post-chroot, and use it in ftpd. [11:07]

Fix a buffer overflow in telnetd. [11:08]

Make pam_ssh ignore unpassphrased keys unless the "nullok" option is
specified. [11:09]

Add sanity checking of service names in pam_start. [11:10]

Approved by:    so (cperciva)
Approved by:    re (bz)
Security:       FreeBSD-SA-11:06.bind
Security:       FreeBSD-SA-11:07.chroot
Security:       FreeBSD-SA-11:08.telnetd
Security:       FreeBSD-SA-11:09.pam_ssh
Security:       FreeBSD-SA-11:10.pam
2011-12-23 15:00:37 +00:00
Gabor Kovesdan
0e6d7a0efa - Fix a trivial bug in iconv. When there is no space to perform the
conversion, conversion must fail and errno must be set to E2BIG.

PR:		standards/160673
Submitted by:	Henning Petersen <henning.petersen@t-online.de>
Reviewed by:	pluknet
Approved by:	re (kib), delphij (mentor)
2011-09-19 22:49:36 +00:00
Alexander Kabaev
472d2173ba Put a quick bandaid on internal citrus locking.
The code is not quite right still, but it programs from deadlocking
on themselves if one enables new citrus code by mistake.
2011-06-19 13:35:46 +00:00
Ulrich Spörlein
135bce2a9e mdoc: reorder sections consistently 2011-06-02 09:56:53 +00:00
Gabor Kovesdan
15a4dfe2a5 - Move some internal functions to the private namespace
Submitted by:	kan
Approved by:	delphij (mentor)
2011-05-27 10:40:34 +00:00
Gabor Kovesdan
ad30f8e79b Add the BSD-licensed Citrus iconv to the base system with default off
setting. It can be built by setting the WITH_ICONV knob. While this
knob is unset, the library part, the binaries, the header file and
the metadata files will not be built or installed so it makes no impact
on the system if left turned off.

This work is based on the iconv implementation in NetBSD but a great
number of improvements and feature additions have been included:

- Some utilities have been added. There is a conversion table generator,
  which can compare conversion tables to reference data generated by
  GNU libiconv. This helps ensuring conversion compatibility.
- UTF-16 surrogate support and some endianness issues have been fixed.
- The rather chaotic Makefiles to build metadata have been refactored
  and cleaned up, now it is easy to read and it is also easier to add
  support for new encodings.
- A bunch of new encodings and encoding aliases have been added.
- Support for 1->2, 1->3 and 1->4 mappings, which is needed for
  transliterating with flying accents as GNU does, like "u.
- Lots of warnings have been fixed, the major part of the code is
  now WARNS=6 clean.
- New section 1 and section 5 manual pages have been added.
- Some GNU-specific calls have been implemented:
  iconvlist(), iconvctl(), iconv_canonicalize(), iconv_open_into()
- Support for GNU's //IGNORE suffix has been added.
- The "-" argument for stdin is now recognized in iconv(1) as per POSIX.
- The Big5 conversion module has been fixed.
- The iconv.h header files is supposed to be compatible with the
  GNU version, i.e. sources should build with base iconv.h and
  GNU libiconv. It also includes a macro magic to deal with the
  char ** and const char ** incompatibility.
- GNU compatibility: "" or "char" means the current local
  encoding in use
- Various cleanups and style(9) fixes.

Approved by:	delphij (mentor)
Obtained from:	The NetBSD Project
Sponsored by:	Google Summer of Code 2009
2011-02-25 00:04:39 +00:00