Print this page
10111 dat_dictionary_create() use after free


  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #pragma ident   "%Z%%M% %I%     %E% SMI"


  32 
  33 /*
  34  *
  35  * MODULE: dat_dictionary.c
  36  *
  37  * PURPOSE: dictionary data structure
  38  *
  39  * $Id: dat_dictionary.c,v 1.11 2003/08/05 19:01:48 jlentini Exp $
  40  */
  41 
  42 
  43 #include "dat_dictionary.h"
  44 
  45 
  46 /*
  47  *
  48  * Structures
  49  *
  50  */
  51 


 127 
 128         /* create the tail node */
 129         p_dictionary->tail = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
 130         if (NULL == p_dictionary->tail)      {
 131                 status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
 132                     DAT_RESOURCE_MEMORY);
 133                 goto bail;
 134         }
 135 
 136         (void) dat_os_memset(p_dictionary->tail, '\0',
 137             sizeof (DAT_DICTIONARY_NODE));
 138 
 139         p_dictionary->head->next = p_dictionary->tail;
 140         p_dictionary->tail->prev = p_dictionary->head;
 141 
 142         *pp_dictionary = p_dictionary;
 143 
 144 bail:
 145         if (DAT_SUCCESS != status) {
 146                 if (NULL != p_dictionary) {
 147                         dat_os_free(p_dictionary, sizeof (DAT_DICTIONARY));
 148 
 149                         if (NULL != p_dictionary->head) {
 150                                 dat_os_free(p_dictionary->head,
 151                                     sizeof (DAT_DICTIONARY_NODE));
 152                         }
 153 
 154                         if (NULL != p_dictionary->tail) {
 155                                 dat_os_free(p_dictionary->tail,
 156                                     sizeof (DAT_DICTIONARY_NODE));
 157                         }


 158                 }

 159         }
 160 
 161         return (status);
 162 }
 163 
 164 
 165 /*
 166  * Function: dat_dictionary_destroy
 167  */
 168 
 169 DAT_RETURN
 170 dat_dictionary_destroy(
 171     IN  DAT_DICTIONARY *p_dictionary)
 172 {
 173         DAT_DICTIONARY_NODE *cur_node;
 174 
 175         dat_os_assert(NULL != p_dictionary);
 176 
 177         while (NULL != p_dictionary->head) {
 178                 cur_node = p_dictionary->head;




  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 /*
  32  * Copyright (c) 2018, Joyent, Inc.
  33  */
  34 
  35 /*
  36  *
  37  * MODULE: dat_dictionary.c
  38  *
  39  * PURPOSE: dictionary data structure
  40  *
  41  * $Id: dat_dictionary.c,v 1.11 2003/08/05 19:01:48 jlentini Exp $
  42  */
  43 
  44 
  45 #include "dat_dictionary.h"
  46 
  47 
  48 /*
  49  *
  50  * Structures
  51  *
  52  */
  53 


 129 
 130         /* create the tail node */
 131         p_dictionary->tail = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
 132         if (NULL == p_dictionary->tail)      {
 133                 status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
 134                     DAT_RESOURCE_MEMORY);
 135                 goto bail;
 136         }
 137 
 138         (void) dat_os_memset(p_dictionary->tail, '\0',
 139             sizeof (DAT_DICTIONARY_NODE));
 140 
 141         p_dictionary->head->next = p_dictionary->tail;
 142         p_dictionary->tail->prev = p_dictionary->head;
 143 
 144         *pp_dictionary = p_dictionary;
 145 
 146 bail:
 147         if (DAT_SUCCESS != status) {
 148                 if (NULL != p_dictionary) {


 149                         if (NULL != p_dictionary->head) {
 150                                 dat_os_free(p_dictionary->head,
 151                                     sizeof (DAT_DICTIONARY_NODE));
 152                         }
 153 
 154                         if (NULL != p_dictionary->tail) {
 155                                 dat_os_free(p_dictionary->tail,
 156                                     sizeof (DAT_DICTIONARY_NODE));
 157                         }
 158 
 159                         dat_os_free(p_dictionary, sizeof (DAT_DICTIONARY));
 160                 }
 161 
 162         }
 163 
 164         return (status);
 165 }
 166 
 167 
 168 /*
 169  * Function: dat_dictionary_destroy
 170  */
 171 
 172 DAT_RETURN
 173 dat_dictionary_destroy(
 174     IN  DAT_DICTIONARY *p_dictionary)
 175 {
 176         DAT_DICTIONARY_NODE *cur_node;
 177 
 178         dat_os_assert(NULL != p_dictionary);
 179 
 180         while (NULL != p_dictionary->head) {
 181                 cur_node = p_dictionary->head;