]>
Commit | Line | Data |
---|---|---|
630da022 | 1 | /* Handling of dynamic string tokens. |
dff8da6b | 2 | Copyright (C) 1999-2024 Free Software Foundation, Inc. |
dc5efe83 UD |
3 | This file is part of the GNU C Library. |
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. | |
dc5efe83 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. |
dc5efe83 | 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/>. */ |
dc5efe83 | 18 | |
4c35fb65 AS |
19 | #include "trusted-dirs.h" |
20 | ||
08769175 UD |
21 | #ifdef SHARED |
22 | # define IS_RTLD(l) (l) == &GL(dl_rtld_map) | |
23 | #else | |
24 | # define IS_RTLD(l) 0 | |
25 | #endif | |
b3fc5f84 | 26 | /* Guess from the number of DSTs the length of the result string. */ |
dc5efe83 UD |
27 | #define DL_DST_REQUIRED(l, name, len, cnt) \ |
28 | ({ \ | |
dc5efe83 | 29 | size_t __len = (len); \ |
d4b04a33 | 30 | size_t __cnt = (cnt); \ |
dc5efe83 | 31 | \ |
d4b04a33 | 32 | if (__cnt > 0) \ |
dc5efe83 | 33 | { \ |
08769175 | 34 | size_t dst_len; \ |
d4b04a33 UD |
35 | /* Now we make a guess how many extra characters on top of the \ |
36 | length of S we need to represent the result. We know that \ | |
37 | we have CNT replacements. Each at most can use \ | |
4c35fb65 AS |
38 | MAX (MAX (strlen (ORIGIN), strlen (_dl_platform)), \ |
39 | strlen (DL_DST_LIB)) \ | |
40 | minus 4 (which is the length of "$LIB"). \ | |
d4b04a33 UD |
41 | \ |
42 | First get the origin string if it is not available yet. \ | |
08769175 UD |
43 | This can only happen for the map of the executable or, when \ |
44 | auditing, in ld.so. */ \ | |
d4b04a33 UD |
45 | if ((l)->l_origin == NULL) \ |
46 | { \ | |
08769175 | 47 | assert ((l)->l_name[0] == '\0' || IS_RTLD (l)); \ |
d4b04a33 | 48 | (l)->l_origin = _dl_get_origin (); \ |
4c35fb65 | 49 | dst_len = ((l)->l_origin && (l)->l_origin != (char *) -1 \ |
d4b04a33 UD |
50 | ? strlen ((l)->l_origin) : 0); \ |
51 | } \ | |
52 | else \ | |
4c35fb65 | 53 | dst_len = (l)->l_origin == (char *) -1 \ |
d4b04a33 | 54 | ? 0 : strlen ((l)->l_origin); \ |
08769175 | 55 | dst_len = MAX (MAX (dst_len, GLRO(dl_platformlen)), \ |
4c35fb65 AS |
56 | strlen (DL_DST_LIB)); \ |
57 | if (dst_len > 4) \ | |
58 | __len += __cnt * (dst_len - 4); \ | |
dc5efe83 | 59 | } \ |
dc5efe83 | 60 | \ |
d4b04a33 | 61 | __len; }) |