Print this page
7214 make buffer under-read while parsing conditional variables
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Robert Mustacchi <rm@joyent.com>


   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 2006 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 /*
  27  *      doname.c
  28  *
  29  *      Figure out which targets are out of date and rebuild them
  30  */
  31 
  32 /*
  33  * Included files
  34  */
  35 #include <alloca.h>               /* alloca() */
  36 #include <fcntl.h>
  37 #include <mk/defs.h>
  38 #include <mksh/i18n.h>            /* get_char_semantics_value() */
  39 #include <mksh/macro.h>           /* getvar(), expand_value() */
  40 #include <mksh/misc.h>            /* getmem() */
  41 #include <poll.h>
  42 #include <libintl.h>
  43 #include <signal.h>


2876 add_pattern_conditionals(register Name target)
2877 {
2878         register Property       conditional;
2879         Property                new_prop;
2880         Property                *previous;
2881         Name_rec                dummy;
2882         wchar_t                 *pattern;
2883         wchar_t                 *percent;
2884         int                     length;
2885 
2886         Wstring wcb(target);
2887         Wstring wcb1;
2888 
2889         for (conditional = get_prop(conditionals->prop, conditional_prop);
2890              conditional != NULL;
2891              conditional = get_prop(conditional->next, conditional_prop)) {
2892                 wcb1.init(conditional->body.conditional.target);
2893                 pattern = wcb1.get_string();
2894                 if (pattern[1] != 0) {
2895                         percent = (wchar_t *) wcschr(pattern, (int) percent_char);




2896                         if (!wcb.equaln(pattern, percent-pattern) ||
2897                             !IS_WEQUAL(wcb.get_string(wcb.length()-wcslen(percent+1)), percent+1)) {
2898                                 continue;
2899                         }
2900                 }
2901                 for (previous = &target->prop;
2902                      *previous != NULL;
2903                      previous = &(*previous)->next) {
2904                         if (((*previous)->type == conditional_prop) &&
2905                             ((*previous)->body.conditional.sequence >
2906                              conditional->body.conditional.sequence)) {
2907                                 break;
2908                         }
2909                 }
2910                 if (*previous == NULL) {
2911                         new_prop = append_prop(target, conditional_prop);
2912                 } else {
2913                         dummy.prop = NULL;
2914                         new_prop = append_prop(&dummy, conditional_prop);
2915                         new_prop->next = *previous;
2916                         *previous = new_prop;
2917                 }




   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 2006 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2016 RackTop Systems.
  26  */
  27 
  28 /*
  29  *      doname.c
  30  *
  31  *      Figure out which targets are out of date and rebuild them
  32  */
  33 
  34 /*
  35  * Included files
  36  */
  37 #include <alloca.h>               /* alloca() */
  38 #include <fcntl.h>
  39 #include <mk/defs.h>
  40 #include <mksh/i18n.h>            /* get_char_semantics_value() */
  41 #include <mksh/macro.h>           /* getvar(), expand_value() */
  42 #include <mksh/misc.h>            /* getmem() */
  43 #include <poll.h>
  44 #include <libintl.h>
  45 #include <signal.h>


2878 add_pattern_conditionals(register Name target)
2879 {
2880         register Property       conditional;
2881         Property                new_prop;
2882         Property                *previous;
2883         Name_rec                dummy;
2884         wchar_t                 *pattern;
2885         wchar_t                 *percent;
2886         int                     length;
2887 
2888         Wstring wcb(target);
2889         Wstring wcb1;
2890 
2891         for (conditional = get_prop(conditionals->prop, conditional_prop);
2892              conditional != NULL;
2893              conditional = get_prop(conditional->next, conditional_prop)) {
2894                 wcb1.init(conditional->body.conditional.target);
2895                 pattern = wcb1.get_string();
2896                 if (pattern[1] != 0) {
2897                         percent = (wchar_t *) wcschr(pattern, (int) percent_char);
2898                         /* Check for possible buffer under-read */
2899                         if ((length = wcb.length()-wcslen(percent+1)) <= 0) {
2900                                 continue;
2901                         }
2902                         if (!wcb.equaln(pattern, percent-pattern) ||
2903                             !IS_WEQUAL(wcb.get_string(length), percent+1)) {
2904                                 continue;
2905                         }
2906                 }
2907                 for (previous = &target->prop;
2908                      *previous != NULL;
2909                      previous = &(*previous)->next) {
2910                         if (((*previous)->type == conditional_prop) &&
2911                             ((*previous)->body.conditional.sequence >
2912                              conditional->body.conditional.sequence)) {
2913                                 break;
2914                         }
2915                 }
2916                 if (*previous == NULL) {
2917                         new_prop = append_prop(target, conditional_prop);
2918                 } else {
2919                         dummy.prop = NULL;
2920                         new_prop = append_prop(&dummy, conditional_prop);
2921                         new_prop->next = *previous;
2922                         *previous = new_prop;
2923                 }