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


   4  * The contents of this file are subject to the terms of the
   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 #include <stdio.h>
  27 #include <fcntl.h>
  28 #include <ctype.h>
  29 #include <string.h>
  30 #include <stdlib.h>
  31 #include <unistd.h>
  32 #include <errno.h>
  33 #include <limits.h>
  34 #include <libintl.h>
  35 #include <locale.h>
  36 #include <sys/stat.h>
  37 #include <sys/corectl.h>
  38 #include <libproc.h>
  39 #include <libscf.h>
  40 #include <libscf_priv.h>
  41 #include <assert.h>
  42 
  43 #define E_SUCCESS       0               /* Exit status for success */


 530         if ((fp = fopen(PATH_CONFIG, "r")) == NULL)
 531                 return (0);
 532 
 533         for (line = 1; fgets(buf, sizeof (buf), fp) != NULL; line++) {
 534                 /*
 535                  * Skip comment lines and empty lines.
 536                  */
 537                 if (buf[0] == '#' || buf[0] == '\n')
 538                         continue;
 539                 /*
 540                  * Look for "name=value", with optional whitespace on either
 541                  * side, terminated by a newline, and consuming the whole line.
 542                  */
 543                 /* LINTED - unbounded string specifier */
 544                 n = sscanf(buf, " %[^=]=%s \n%n", name, value, &len);
 545                 if (n >= 1 && name[0] != '\0' &&
 546                     (n == 1 || len == strlen(buf))) {
 547                         if (n == 1)
 548                                 value[0] = '\0';
 549                         if (strcmp(name, "COREADM_GLOB_PATTERN") == 0) {
 550                                 (void) strcpy(gpattern, value);

 551                                 continue;
 552                         }
 553                         if (strcmp(name, "COREADM_GLOB_CONTENT") == 0) {
 554                                 (void) proc_str2content(value, &glob_content);
 555                                 continue;
 556                         }
 557                         if (strcmp(name, "COREADM_INIT_PATTERN") == 0) {
 558                                 (void) strcpy(ipattern, value);

 559                                 continue;
 560                         }
 561                         if (strcmp(name, "COREADM_INIT_CONTENT") == 0) {
 562                                 (void) proc_str2content(value, &init_content);
 563                                 continue;
 564                         }
 565                         if (strcmp(name, "COREADM_GLOB_ENABLED") == 0) {
 566                                 if (yes(name, value, line))
 567                                         options |= CC_GLOBAL_PATH;
 568                                 continue;
 569                         }
 570                         if (strcmp(name, "COREADM_PROC_ENABLED") == 0) {
 571                                 if (yes(name, value, line))
 572                                         options |= CC_PROCESS_PATH;
 573                                 else
 574                                         options &= ~CC_PROCESS_PATH;
 575                                 continue;
 576                         }
 577                         if (strcmp(name, "COREADM_GLOB_SETID_ENABLED") == 0) {
 578                                 if (yes(name, value, line))




   4  * The contents of this file are subject to the terms of the
   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright (c) 2018, Joyent, Inc.
  25  */
  26 
  27 #include <stdio.h>
  28 #include <fcntl.h>
  29 #include <ctype.h>
  30 #include <string.h>
  31 #include <stdlib.h>
  32 #include <unistd.h>
  33 #include <errno.h>
  34 #include <limits.h>
  35 #include <libintl.h>
  36 #include <locale.h>
  37 #include <sys/stat.h>
  38 #include <sys/corectl.h>
  39 #include <libproc.h>
  40 #include <libscf.h>
  41 #include <libscf_priv.h>
  42 #include <assert.h>
  43 
  44 #define E_SUCCESS       0               /* Exit status for success */


 531         if ((fp = fopen(PATH_CONFIG, "r")) == NULL)
 532                 return (0);
 533 
 534         for (line = 1; fgets(buf, sizeof (buf), fp) != NULL; line++) {
 535                 /*
 536                  * Skip comment lines and empty lines.
 537                  */
 538                 if (buf[0] == '#' || buf[0] == '\n')
 539                         continue;
 540                 /*
 541                  * Look for "name=value", with optional whitespace on either
 542                  * side, terminated by a newline, and consuming the whole line.
 543                  */
 544                 /* LINTED - unbounded string specifier */
 545                 n = sscanf(buf, " %[^=]=%s \n%n", name, value, &len);
 546                 if (n >= 1 && name[0] != '\0' &&
 547                     (n == 1 || len == strlen(buf))) {
 548                         if (n == 1)
 549                                 value[0] = '\0';
 550                         if (strcmp(name, "COREADM_GLOB_PATTERN") == 0) {
 551                                 (void) strlcpy(gpattern, value,
 552                                     sizeof (gpattern));
 553                                 continue;
 554                         }
 555                         if (strcmp(name, "COREADM_GLOB_CONTENT") == 0) {
 556                                 (void) proc_str2content(value, &glob_content);
 557                                 continue;
 558                         }
 559                         if (strcmp(name, "COREADM_INIT_PATTERN") == 0) {
 560                                 (void) strlcpy(ipattern, value,
 561                                     sizeof (ipattern));
 562                                 continue;
 563                         }
 564                         if (strcmp(name, "COREADM_INIT_CONTENT") == 0) {
 565                                 (void) proc_str2content(value, &init_content);
 566                                 continue;
 567                         }
 568                         if (strcmp(name, "COREADM_GLOB_ENABLED") == 0) {
 569                                 if (yes(name, value, line))
 570                                         options |= CC_GLOBAL_PATH;
 571                                 continue;
 572                         }
 573                         if (strcmp(name, "COREADM_PROC_ENABLED") == 0) {
 574                                 if (yes(name, value, line))
 575                                         options |= CC_PROCESS_PATH;
 576                                 else
 577                                         options &= ~CC_PROCESS_PATH;
 578                                 continue;
 579                         }
 580                         if (strcmp(name, "COREADM_GLOB_SETID_ENABLED") == 0) {
 581                                 if (yes(name, value, line))