Fix assertion when handling DSTs during auditing.
[glibc.git] / elf / dl-dst.h
blob9d219e2cb38208230a411445c06f3f28a9aaa26b
1 /* Handling of dynamic sring tokens.
2 Copyright (C) 1999,2001-2004,2006,2007,2011 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include "trusted-dirs.h"
22 /* Determine the number of DST elements in the name. Only if IS_PATH is
23 nonzero paths are recognized (i.e., multiple, ':' separated filenames). */
24 #define DL_DST_COUNT(name, is_path) \
25 ({ \
26 size_t __cnt = 0; \
27 const char *__sf = strchr (name, '$'); \
29 if (__builtin_expect (__sf != NULL, 0)) \
30 __cnt = _dl_dst_count (__sf, is_path); \
32 __cnt; })
35 #ifdef SHARED
36 # define IS_RTLD(l) (l) == &GL(dl_rtld_map)
37 #else
38 # define IS_RTLD(l) 0
39 #endif
40 /* Guess from the number of DSTs the length of the result string. */
41 #define DL_DST_REQUIRED(l, name, len, cnt) \
42 ({ \
43 size_t __len = (len); \
44 size_t __cnt = (cnt); \
46 if (__cnt > 0) \
47 { \
48 size_t dst_len; \
49 /* Now we make a guess how many extra characters on top of the \
50 length of S we need to represent the result. We know that \
51 we have CNT replacements. Each at most can use \
52 MAX (MAX (strlen (ORIGIN), strlen (_dl_platform)), \
53 strlen (DL_DST_LIB)) \
54 minus 4 (which is the length of "$LIB"). \
56 First get the origin string if it is not available yet. \
57 This can only happen for the map of the executable or, when \
58 auditing, in ld.so. */ \
59 DL_DST_REQ_STATIC (l) \
60 if ((l)->l_origin == NULL) \
61 { \
62 assert ((l)->l_name[0] == '\0' || IS_RTLD (l)); \
63 (l)->l_origin = _dl_get_origin (); \
64 dst_len = ((l)->l_origin && (l)->l_origin != (char *) -1 \
65 ? strlen ((l)->l_origin) : 0); \
66 } \
67 else \
68 dst_len = (l)->l_origin == (char *) -1 \
69 ? 0 : strlen ((l)->l_origin); \
70 dst_len = MAX (MAX (dst_len, GLRO(dl_platformlen)), \
71 strlen (DL_DST_LIB)); \
72 if (dst_len > 4) \
73 __len += __cnt * (dst_len - 4); \
74 } \
76 __len; })
78 #ifdef SHARED
79 # define DL_DST_REQ_STATIC(l) /* nothing */
80 #else
81 # define DL_DST_REQ_STATIC(l) \
82 if ((l) == NULL) \
83 { \
84 const char *origin = _dl_get_origin (); \
85 dst_len = (origin && origin != (char *) -1 ? strlen (origin) : 0); \
86 } \
87 else
88 #endif