Print this page
11924 infinite loop in mdb ::load
Reviewed by: John Levon <john.levon@joyent.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  * Copyright (c) 2012 Joyent, Inc. All rights reserved.
  26  */
  27 
  28 #include <sys/param.h>
  29 #include <unistd.h>
  30 #include <strings.h>
  31 #include <dlfcn.h>
  32 #include <ctype.h>
  33 #include <link.h>
  34 
  35 #include <mdb/mdb_module.h>
  36 #include <mdb/mdb_modapi.h>
  37 #include <mdb/mdb_debug.h>
  38 #include <mdb/mdb_string.h>
  39 #include <mdb/mdb_err.h>
  40 #include <mdb/mdb_io.h>
  41 #include <mdb/mdb_frame.h>
  42 #include <mdb/mdb.h>
  43 
  44 int
  45 mdb_module_load(const char *name, int mode)
  46 {
  47         const char *wformat = "no module '%s' could be found\n";
  48         const char *fullname = NULL;
  49         char buf[MAXPATHLEN], *p, *q;
  50         int i;
  51 
  52         ASSERT(!(mode & MDB_MOD_DEFER));
  53 
  54         if (strchr(name, '/') != NULL) {
  55                 ASSERT(!(mode & MDB_MOD_BUILTIN));
  56 
  57                 (void) mdb_iob_snprintf(buf, sizeof (buf), "%s",
  58                     strbasename(name));
  59 
  60                 /*
  61                  * Remove any .so(.[0-9]+)? suffix
  62                  */
  63                 while ((p = strrchr(buf, '.')) != NULL) {
  64                         for (q = p + 1; isdigit(*q); q++)
  65                                 ;
  66 
  67                         if (*q == '\0') {


  68                                 /* found digits to remove */
  69                                 *p = '\0';
  70                                 continue;
  71                         }
  72 

  73                         if (strcmp(p, ".so") == 0) {
  74                                 *p = '\0';
  75                                 break;
  76                         }
  77 
  78                 }

  79                 fullname = name;
  80                 name = buf;
  81         }
  82 
  83         if (!mdb_module_validate_name(name, &wformat))
  84                 goto err;
  85 
  86         if (fullname != NULL) {
  87                 if (access(fullname, F_OK) != 0) {
  88                         name = fullname; /* for warn() below */
  89                         goto err;
  90                 }
  91                 return (mdb_module_create(name, fullname, mode, NULL));
  92         }
  93 
  94         /*
  95          * If a simple name is specified, search for it in the module path.
  96          * The module path is searched in order, and for each element we
  97          * look for the following files:
  98          *




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  * Copyright 2019 Joyent, Inc.
  26  */
  27 
  28 #include <sys/param.h>
  29 #include <unistd.h>
  30 #include <strings.h>
  31 #include <dlfcn.h>
  32 #include <ctype.h>
  33 #include <link.h>
  34 
  35 #include <mdb/mdb_module.h>
  36 #include <mdb/mdb_modapi.h>
  37 #include <mdb/mdb_debug.h>
  38 #include <mdb/mdb_string.h>
  39 #include <mdb/mdb_err.h>
  40 #include <mdb/mdb_io.h>
  41 #include <mdb/mdb_frame.h>
  42 #include <mdb/mdb.h>
  43 
  44 int
  45 mdb_module_load(const char *name, int mode)
  46 {
  47         const char *wformat = "no module '%s' could be found\n";
  48         const char *fullname = NULL;
  49         char buf[MAXPATHLEN], *p, *q;
  50         int i;
  51 
  52         ASSERT(!(mode & MDB_MOD_DEFER));
  53 
  54         if (strchr(name, '/') != NULL) {
  55                 ASSERT(!(mode & MDB_MOD_BUILTIN));
  56 
  57                 (void) mdb_iob_snprintf(buf, sizeof (buf), "%s",
  58                     strbasename(name));
  59 
  60                 /*
  61                  * Remove any .so(.[0-9]+)? suffix
  62                  */
  63                 if ((p = strrchr(buf, '.')) != NULL) {
  64                         for (q = p + 1; isdigit(*q); q++)
  65                                 ;
  66 
  67                         if (*q == '\0') {
  68                                 if (q > p + 1) {
  69 
  70                                         /* found digits to remove */
  71                                         *p = '\0';

  72                                 }
  73                         }
  74                         if ((p = strrchr(buf, '.')) != NULL) {
  75                                 if (strcmp(p, ".so") == 0) {
  76                                         *p = '\0';

  77                                 }

  78                         }
  79                 }
  80                 fullname = name;
  81                 name = buf;
  82         }
  83 
  84         if (!mdb_module_validate_name(name, &wformat))
  85                 goto err;
  86 
  87         if (fullname != NULL) {
  88                 if (access(fullname, F_OK) != 0) {
  89                         name = fullname; /* for warn() below */
  90                         goto err;
  91                 }
  92                 return (mdb_module_create(name, fullname, mode, NULL));
  93         }
  94 
  95         /*
  96          * If a simple name is specified, search for it in the module path.
  97          * The module path is searched in order, and for each element we
  98          * look for the following files:
  99          *