Fix another x86 sys/ucontext.h namespace issue (bug 21457).
[glibc.git] / nss / rewrite_field.c
blobc0ae3d23f2d7b572c575fe4eba3cd8bb792bd608
1 /* Copyright (C) 2015-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <nss.h>
19 #include <string.h>
21 /* Rewrite VALUE to a valid field value in the NSS database. Invalid
22 characters are replaced with a single space character ' '. If
23 VALUE is NULL, the empty string is returned. *TO_BE_FREED is
24 overwritten with a pointer the caller has to free if the function
25 returns successfully. On failure, return NULL. */
26 const char *
27 internal_function
28 __nss_rewrite_field (const char *value, char **to_be_freed)
30 *to_be_freed = NULL;
31 if (value == NULL)
32 return "";
34 /* Search for non-allowed characters. */
35 const char *p = strpbrk (value, __nss_invalid_field_characters);
36 if (p == NULL)
37 return value;
38 *to_be_freed = __strdup (value);
39 if (*to_be_freed == NULL)
40 return NULL;
42 /* Switch pointer to freshly-allocated buffer. */
43 char *bad = *to_be_freed + (p - value);
46 *bad = ' ';
47 bad = strpbrk (bad + 1, __nss_invalid_field_characters);
49 while (bad != NULL);
51 return *to_be_freed;