Print this page
10127 coreadm is mis-using strcpy()

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/coreadm/coreadm.c
          +++ new/usr/src/cmd/coreadm/coreadm.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + * Copyright (c) 2018, Joyent, Inc.
  24   25   */
  25   26  
  26   27  #include <stdio.h>
  27   28  #include <fcntl.h>
  28   29  #include <ctype.h>
  29   30  #include <string.h>
  30   31  #include <stdlib.h>
  31   32  #include <unistd.h>
  32   33  #include <errno.h>
  33   34  #include <limits.h>
↓ open down ↓ 506 lines elided ↑ open up ↑
 540  541                   * Look for "name=value", with optional whitespace on either
 541  542                   * side, terminated by a newline, and consuming the whole line.
 542  543                   */
 543  544                  /* LINTED - unbounded string specifier */
 544  545                  n = sscanf(buf, " %[^=]=%s \n%n", name, value, &len);
 545  546                  if (n >= 1 && name[0] != '\0' &&
 546  547                      (n == 1 || len == strlen(buf))) {
 547  548                          if (n == 1)
 548  549                                  value[0] = '\0';
 549  550                          if (strcmp(name, "COREADM_GLOB_PATTERN") == 0) {
 550      -                                (void) strcpy(gpattern, value);
      551 +                                (void) strlcpy(gpattern, value,
      552 +                                    sizeof (gpattern));
 551  553                                  continue;
 552  554                          }
 553  555                          if (strcmp(name, "COREADM_GLOB_CONTENT") == 0) {
 554  556                                  (void) proc_str2content(value, &glob_content);
 555  557                                  continue;
 556  558                          }
 557  559                          if (strcmp(name, "COREADM_INIT_PATTERN") == 0) {
 558      -                                (void) strcpy(ipattern, value);
      560 +                                (void) strlcpy(ipattern, value,
      561 +                                    sizeof (ipattern));
 559  562                                  continue;
 560  563                          }
 561  564                          if (strcmp(name, "COREADM_INIT_CONTENT") == 0) {
 562  565                                  (void) proc_str2content(value, &init_content);
 563  566                                  continue;
 564  567                          }
 565  568                          if (strcmp(name, "COREADM_GLOB_ENABLED") == 0) {
 566  569                                  if (yes(name, value, line))
 567  570                                          options |= CC_GLOBAL_PATH;
 568  571                                  continue;
↓ open down ↓ 119 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX