Print this page
11924 infinite loop in mdb ::load
Reviewed by: John Levon <john.levon@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/mdb/mdb_module_load.c
+++ new/usr/src/cmd/mdb/common/mdb/mdb_module_load.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 - * Copyright (c) 2012 Joyent, Inc. All rights reserved.
25 + * Copyright 2019 Joyent, Inc.
26 26 */
27 27
28 28 #include <sys/param.h>
29 29 #include <unistd.h>
30 30 #include <strings.h>
31 31 #include <dlfcn.h>
32 32 #include <ctype.h>
33 33 #include <link.h>
34 34
35 35 #include <mdb/mdb_module.h>
36 36 #include <mdb/mdb_modapi.h>
37 37 #include <mdb/mdb_debug.h>
38 38 #include <mdb/mdb_string.h>
39 39 #include <mdb/mdb_err.h>
40 40 #include <mdb/mdb_io.h>
41 41 #include <mdb/mdb_frame.h>
42 42 #include <mdb/mdb.h>
43 43
44 44 int
45 45 mdb_module_load(const char *name, int mode)
46 46 {
47 47 const char *wformat = "no module '%s' could be found\n";
48 48 const char *fullname = NULL;
49 49 char buf[MAXPATHLEN], *p, *q;
50 50 int i;
51 51
52 52 ASSERT(!(mode & MDB_MOD_DEFER));
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
53 53
54 54 if (strchr(name, '/') != NULL) {
55 55 ASSERT(!(mode & MDB_MOD_BUILTIN));
56 56
57 57 (void) mdb_iob_snprintf(buf, sizeof (buf), "%s",
58 58 strbasename(name));
59 59
60 60 /*
61 61 * Remove any .so(.[0-9]+)? suffix
62 62 */
63 - while ((p = strrchr(buf, '.')) != NULL) {
63 + if ((p = strrchr(buf, '.')) != NULL) {
64 64 for (q = p + 1; isdigit(*q); q++)
65 65 ;
66 66
67 67 if (*q == '\0') {
68 - /* found digits to remove */
69 - *p = '\0';
70 - continue;
71 - }
68 + if (q > p + 1) {
72 69
73 - if (strcmp(p, ".so") == 0) {
74 - *p = '\0';
75 - break;
70 + /* found digits to remove */
71 + *p = '\0';
72 + }
76 73 }
77 -
74 + if ((p = strrchr(buf, '.')) != NULL) {
75 + if (strcmp(p, ".so") == 0) {
76 + *p = '\0';
77 + }
78 + }
78 79 }
79 80 fullname = name;
80 81 name = buf;
81 82 }
82 83
83 84 if (!mdb_module_validate_name(name, &wformat))
84 85 goto err;
85 86
86 87 if (fullname != NULL) {
87 88 if (access(fullname, F_OK) != 0) {
88 89 name = fullname; /* for warn() below */
89 90 goto err;
90 91 }
91 92 return (mdb_module_create(name, fullname, mode, NULL));
92 93 }
93 94
94 95 /*
95 96 * If a simple name is specified, search for it in the module path.
96 97 * The module path is searched in order, and for each element we
97 98 * look for the following files:
98 99 *
99 100 * 1. If the module name ends in ".so(.[0-9]+)?", search for the literal
100 101 * name and then search for the name without the [0-9]+ suffix.
101 102 * 2. If the module name ends in ".so", search for the literal name.
102 103 * 3. Search for the module name with ".so" appended.
103 104 *
104 105 * Once a matching file is detected, we attempt to load that module
105 106 * and do not resume our search in the case of an error.
106 107 */
107 108 for (i = 0; mdb.m_lpath[i] != NULL; i++) {
108 109 if ((p = strrchr(name, '.')) != NULL && *++p != '\0') {
109 110 if (strisnum(p) || strcmp(p, "so") == 0) {
110 111 (void) mdb_iob_snprintf(buf, sizeof (buf),
111 112 "%s/%s", mdb.m_lpath[i], name);
112 113 mdb_dprintf(MDB_DBG_MODULE,
113 114 "checking for %s\n", buf);
114 115 if (access(buf, F_OK) == 0) {
115 116 return (mdb_module_create(name, buf,
116 117 mode, NULL));
117 118 }
118 119 }
119 120
120 121 while (strisnum(p) && (p = strrchr(buf, '.')) != NULL) {
121 122 *p = '\0'; /* strip trailing digits */
122 123 mdb_dprintf(MDB_DBG_MODULE,
123 124 "checking for %s\n", buf);
124 125 if (access(buf, F_OK) == 0) {
125 126 return (mdb_module_create(name, buf,
126 127 mode, NULL));
127 128 }
128 129 }
129 130 }
130 131
131 132 (void) mdb_iob_snprintf(buf, sizeof (buf), "%s/%s.so",
132 133 mdb.m_lpath[i], name);
133 134
134 135 mdb_dprintf(MDB_DBG_MODULE, "checking for %s\n", buf);
135 136
136 137 if (access(buf, F_OK) == 0)
137 138 return (mdb_module_create(name, buf, mode, NULL));
138 139 }
139 140 err:
140 141 if (!(mode & MDB_MOD_SILENT))
141 142 warn(wformat, name);
142 143
143 144 return (-1);
144 145 }
145 146
146 147 typedef struct mdb_modload_data {
147 148 int mld_first;
148 149 int mld_mode;
149 150 } mdb_modload_data_t;
150 151
151 152 /*ARGSUSED*/
152 153 static int
153 154 module_load(void *fp, const mdb_map_t *map, const char *fullname)
154 155 {
155 156 mdb_modload_data_t *mld = fp;
156 157 const char *name = strbasename(fullname);
157 158
158 159 if (mdb_module_load(name, mld->mld_mode) == 0 && mdb.m_term != NULL) {
159 160 if (mld->mld_first == TRUE) {
160 161 mdb_iob_puts(mdb.m_out, "Loading modules: [");
161 162 mld->mld_first = FALSE;
162 163 }
163 164 mdb_iob_printf(mdb.m_out, " %s", name);
164 165 mdb_iob_flush(mdb.m_out);
165 166 }
166 167
167 168 if (strstr(fullname, "/libc/") != NULL) {
168 169 /*
169 170 * A bit of a kludge: because we manage alternately capable
170 171 * libc instances by mounting the appropriately capable
171 172 * instance over /lib/libc.so.1, we may find that our object
172 173 * list does not contain libc.so.1, but rather one of its
173 174 * hwcap variants. Unfortunately, there is not a way of
174 175 * getting from this shared object to the object that it is
175 176 * effectively interposing on -- which means that without
176 177 * special processing, we will not load any libc.so dmod. So
177 178 * if we see that we have a shared object coming out of the
178 179 * "libc" directory, we assume that we have a "libc-like"
179 180 * object, and explicitly load the "libc.so" dmod.
180 181 */
181 182 return (module_load(fp, map, "libc.so.1"));
182 183 }
183 184
184 185 return (0);
185 186 }
186 187
187 188 void
188 189 mdb_module_load_all(int mode)
189 190 {
190 191 uint_t oflag = mdb_iob_getflags(mdb.m_out) & MDB_IOB_PGENABLE;
191 192 mdb_modload_data_t mld;
192 193
193 194 mld.mld_first = TRUE;
194 195 mld.mld_mode = mode | MDB_MOD_LOCAL | MDB_MOD_SILENT;
195 196
196 197 mdb_iob_clrflags(mdb.m_out, oflag);
197 198
198 199 (void) mdb_tgt_object_iter(mdb.m_target, module_load, &mld);
199 200
200 201 if (mdb.m_term != NULL && mld.mld_first == FALSE)
201 202 mdb_iob_puts(mdb.m_out, " ]\n");
202 203
203 204 mdb_iob_setflags(mdb.m_out, oflag);
204 205 }
205 206
206 207 /*ARGSUSED*/
207 208 int
208 209 mdb_module_unload(const char *name, int mode)
209 210 {
210 211 ASSERT((mode & ~MDB_MOD_SILENT) == 0);
211 212
212 213 return (mdb_module_unload_common(name));
213 214 }
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX