]> sourceware.org Git - glibc.git/blame - iconv/gconv_charset.h
syslog: Fix integer overflow in __vsyslog_internal (CVE-2023-6780)
[glibc.git] / iconv / gconv_charset.h
CommitLineData
e7f21fa6 1/* Charset name normalization.
dff8da6b 2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
e7f21fa6 3 This file is part of the GNU C Library.
e7f21fa6
UD
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
e7f21fa6
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
e7f21fa6 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
e7f21fa6
UD
18
19#include <ctype.h>
5db91571 20#include <locale.h>
91927b7c
AS
21#include <stdbool.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <stdlib.h>
25#include "gconv_int.h"
e7f21fa6
UD
26
27
91927b7c
AS
28/* An iconv encoding is in the form of a triplet, with parts separated by
29 a '/' character. The first part is the standard name, the second part is
30 the character set, and the third part is the error handler. If the first
31 part is sufficient to identify both the standard and the character set
32 then the second part can be empty e.g. UTF-8//. If the first part is not
33 sufficient to identify both the standard and the character set then the
34 second part is required e.g. ISO-10646/UTF8/. If neither the first or
35 second parts are provided e.g. //, then the current locale is used.
36 The actual values used in the first and second parts are not entirely
37 relevant to the implementation. The values themselves are used in a hash
38 table to lookup modules and so the naming convention of the first two parts
39 is somewhat arbitrary and only helps locate the entries in the cache.
40 The third part is the error handler and is comprised of a ',' or '/'
41 separated list of suffixes. Currently, we support "TRANSLIT" for
42 transliteration and "IGNORE" for ignoring conversion errors due to
43 unrecognized input characters. */
44#define GCONV_TRIPLE_SEPARATOR "/"
45#define GCONV_SUFFIX_SEPARATOR ","
46#define GCONV_TRANSLIT_SUFFIX "TRANSLIT"
47#define GCONV_IGNORE_ERRORS_SUFFIX "IGNORE"
48
49
91927b7c 50/* This function copies in-order, characters from the source 's' that are
f58a8c1c 51 either alphanumeric or one in one of these: "_-.,:/" - into the destination
91927b7c
AS
52 'wp' while dropping all other characters. In the process, it converts all
53 alphabetical characters to upper case. It then appends up to two '/'
54 characters so that the total number of '/'es in the destination is 2. */
55static inline void __attribute__ ((unused, always_inline))
e7f21fa6
UD
56strip (char *wp, const char *s)
57{
58 int slash_count = 0;
59
60 while (*s != '\0')
61 {
4b5b009c 62 if (__isalnum_l (*s, _nl_C_locobj_ptr)
82faa177 63 || *s == '_' || *s == '-' || *s == '.' || *s == ',' || *s == ':')
4b5b009c 64 *wp++ = __toupper_l (*s, _nl_C_locobj_ptr);
e7f21fa6
UD
65 else if (*s == '/')
66 {
67 if (++slash_count == 3)
68 break;
69 *wp++ = '/';
70 }
71 ++s;
72 }
73
74 while (slash_count++ < 2)
75 *wp++ = '/';
76
77 *wp = '\0';
78}
79
80
dd9423a6 81static inline char * __attribute__ ((unused, always_inline))
e7f21fa6
UD
82upstr (char *dst, const char *str)
83{
84 char *cp = dst;
4b5b009c 85 while ((*cp++ = __toupper_l (*str++, _nl_C_locobj_ptr)) != '\0')
e7f21fa6
UD
86 /* nothing */;
87 return dst;
88}
This page took 0.455795 seconds and 5 git commands to generate.