Print this page
10124 smatch fixes for cryptoadm


   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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright 2010 Nexenta Systems, Inc.  All rights resrved.

  26  */
  27 
  28 #include <cryptoutil.h>
  29 #include <fcntl.h>
  30 #include <libintl.h>
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <strings.h>
  34 #include <unistd.h>
  35 #include <errno.h>
  36 #include <dlfcn.h>
  37 #include <link.h>
  38 #include <sys/types.h>
  39 #include <sys/stat.h>
  40 #include <security/cryptoki.h>
  41 #include "cryptoadm.h"
  42 
  43 #define HDR1 "                                     P\n"
  44 #define HDR2 "                         S     V  K  a     U  D\n"
  45 #define HDR3 "                         i     e  e  i     n  e\n"


 144  * The list of mechanism names to be converted is provided in the
 145  * "mlist" argument.  The list of converted mechanism IDs is returned
 146  * in the "pmech_list" argument.
 147  *
 148  * This function is called by list_metaslot_info() and
 149  * list_mechlist_for_lib() functions.
 150  */
 151 int
 152 convert_mechlist(CK_MECHANISM_TYPE **pmech_list, CK_ULONG *mech_count,
 153     mechlist_t *mlist)
 154 {
 155         int i, n = 0;
 156         mechlist_t *p = mlist;
 157 
 158         while (p != NULL) {
 159                 p = p->next;
 160                 n++;
 161         }
 162 
 163         *pmech_list = malloc(n * sizeof (CK_MECHANISM_TYPE));
 164         if (pmech_list == NULL) {
 165                 cryptodebug("out of memory");
 166                 return (FAILURE);
 167         }
 168         p = mlist;
 169         for (i = 0; i < n; i++) {
 170                 if (pkcs11_str2mech(p->name, &(*pmech_list[i])) != CKR_OK) {
 171                         free(*pmech_list);
 172                         return (FAILURE);
 173                 }
 174                 p = p->next;
 175         }
 176         *mech_count = n;
 177         return (SUCCESS);
 178 }
 179 
 180 /*
 181  * Display the mechanism list for a user-level library
 182  */
 183 int
 184 list_mechlist_for_lib(char *libname, mechlist_t *mlist,




   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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright 2010 Nexenta Systems, Inc.  All rights resrved.
  26  * Copyright (c) 2018, Joyent, Inc.
  27  */
  28 
  29 #include <cryptoutil.h>
  30 #include <fcntl.h>
  31 #include <libintl.h>
  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <strings.h>
  35 #include <unistd.h>
  36 #include <errno.h>
  37 #include <dlfcn.h>
  38 #include <link.h>
  39 #include <sys/types.h>
  40 #include <sys/stat.h>
  41 #include <security/cryptoki.h>
  42 #include "cryptoadm.h"
  43 
  44 #define HDR1 "                                     P\n"
  45 #define HDR2 "                         S     V  K  a     U  D\n"
  46 #define HDR3 "                         i     e  e  i     n  e\n"


 145  * The list of mechanism names to be converted is provided in the
 146  * "mlist" argument.  The list of converted mechanism IDs is returned
 147  * in the "pmech_list" argument.
 148  *
 149  * This function is called by list_metaslot_info() and
 150  * list_mechlist_for_lib() functions.
 151  */
 152 int
 153 convert_mechlist(CK_MECHANISM_TYPE **pmech_list, CK_ULONG *mech_count,
 154     mechlist_t *mlist)
 155 {
 156         int i, n = 0;
 157         mechlist_t *p = mlist;
 158 
 159         while (p != NULL) {
 160                 p = p->next;
 161                 n++;
 162         }
 163 
 164         *pmech_list = malloc(n * sizeof (CK_MECHANISM_TYPE));
 165         if (*pmech_list == NULL) {
 166                 cryptodebug("out of memory");
 167                 return (FAILURE);
 168         }
 169         p = mlist;
 170         for (i = 0; i < n; i++) {
 171                 if (pkcs11_str2mech(p->name, &(*pmech_list[i])) != CKR_OK) {
 172                         free(*pmech_list);
 173                         return (FAILURE);
 174                 }
 175                 p = p->next;
 176         }
 177         *mech_count = n;
 178         return (SUCCESS);
 179 }
 180 
 181 /*
 182  * Display the mechanism list for a user-level library
 183  */
 184 int
 185 list_mechlist_for_lib(char *libname, mechlist_t *mlist,