Print this page
10145 smbios_info_boot() gets NULL check wrong


   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 /*
  23  * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
  24  * Copyright (c) 2017, Joyent, Inc.
  25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 /*
  30  * SMBIOS Information Routines
  31  *
  32  * The routines in this file are used to convert from the SMBIOS data format to
  33  * a more reasonable and stable set of structures offered as part of our ABI.
  34  * These functions take the general form:
  35  *
  36  *      stp = smb_lookup_type(shp, foo);
  37  *      smb_foo_t foo;
  38  *
  39  *      smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
  40  *      bzero(caller's struct);
  41  *
  42  *      copy/convert foo members into caller's struct
  43  *
  44  * We copy the internal structure on to an automatic variable so as to avoid


 966         smb_hwsec_t hs;
 967 
 968         if (stp == NULL)
 969                 return (-1); /* errno is set for us */
 970 
 971         smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
 972         bzero(hsp, sizeof (smbios_hwsec_t));
 973 
 974         hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
 975         hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
 976         hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
 977         hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
 978 
 979         return (stp->smbst_hdr->smbh_hdl);
 980 }
 981 
 982 id_t
 983 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
 984 {
 985         const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
 986         const smb_boot_t *b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
 987 
 988         if (stp == NULL)
 989                 return (-1); /* errno is set for us */
 990 
 991         bzero(bp, sizeof (smbios_boot_t));
 992 


 993         bp->smbt_status = b->smbbo_status[0];
 994         bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
 995         bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
 996 
 997         return (stp->smbst_hdr->smbh_hdl);
 998 }
 999 
1000 id_t
1001 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
1002 {
1003         const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
1004         smb_ipmi_t i;
1005 
1006         if (stp == NULL)
1007                 return (-1); /* errno is set for us */
1008 
1009         smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
1010         bzero(ip, sizeof (smbios_ipmi_t));
1011 
1012         ip->smbip_type = i.smbipm_type;




   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 /*
  23  * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
  24  * Copyright (c) 2018, Joyent, Inc.
  25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 /*
  30  * SMBIOS Information Routines
  31  *
  32  * The routines in this file are used to convert from the SMBIOS data format to
  33  * a more reasonable and stable set of structures offered as part of our ABI.
  34  * These functions take the general form:
  35  *
  36  *      stp = smb_lookup_type(shp, foo);
  37  *      smb_foo_t foo;
  38  *
  39  *      smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
  40  *      bzero(caller's struct);
  41  *
  42  *      copy/convert foo members into caller's struct
  43  *
  44  * We copy the internal structure on to an automatic variable so as to avoid


 966         smb_hwsec_t hs;
 967 
 968         if (stp == NULL)
 969                 return (-1); /* errno is set for us */
 970 
 971         smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
 972         bzero(hsp, sizeof (smbios_hwsec_t));
 973 
 974         hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
 975         hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
 976         hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
 977         hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
 978 
 979         return (stp->smbst_hdr->smbh_hdl);
 980 }
 981 
 982 id_t
 983 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
 984 {
 985         const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
 986         const smb_boot_t *b;
 987 
 988         if (stp == NULL)
 989                 return (-1); /* errno is set for us */
 990 
 991         bzero(bp, sizeof (smbios_boot_t));
 992 
 993         b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
 994 
 995         bp->smbt_status = b->smbbo_status[0];
 996         bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
 997         bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
 998 
 999         return (stp->smbst_hdr->smbh_hdl);
1000 }
1001 
1002 id_t
1003 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
1004 {
1005         const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
1006         smb_ipmi_t i;
1007 
1008         if (stp == NULL)
1009                 return (-1); /* errno is set for us */
1010 
1011         smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
1012         bzero(ip, sizeof (smbios_ipmi_t));
1013 
1014         ip->smbip_type = i.smbipm_type;