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
↓ 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>
↓ 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) {
↓ open down ↓ 126 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX