Print this page
10100 Illumos is confused about calloc() arguments

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libefi/common/rdwr_efi.c
          +++ new/usr/src/lib/libefi/common/rdwr_efi.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  25   25   * Copyright 2014 Toomas Soome <tsoome@me.com>
  26   26   * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
       27 + * Copyright (c) 2018, Joyent, Inc.
  27   28   */
  28   29  
  29   30  #include <stdio.h>
  30   31  #include <stdlib.h>
  31   32  #include <errno.h>
  32   33  #include <strings.h>
  33   34  #include <unistd.h>
  34   35  #include <smbios.h>
  35   36  #include <uuid/uuid.h>
  36   37  #include <libintl.h>
↓ open down ↓ 144 lines elided ↑ open up ↑
 181  182                          (void) fprintf(stderr,
 182  183                          "the maximum number of partitions supported is %lu\n",
 183  184                              MAX_PARTS);
 184  185                  }
 185  186                  return (-1);
 186  187          }
 187  188  
 188  189          length = sizeof (struct dk_gpt) +
 189  190              sizeof (struct dk_part) * (nparts - 1);
 190  191  
 191      -        if ((*vtoc = calloc(length, 1)) == NULL)
      192 +        if ((*vtoc = calloc(1, length)) == NULL)
 192  193                  return (-1);
 193  194  
 194  195          vptr = *vtoc;
 195  196  
 196  197          vptr->efi_version = EFI_VERSION_CURRENT;
 197  198          vptr->efi_lbasize = lbsize;
 198  199          vptr->efi_nparts = nparts;
 199  200          /*
 200  201           * add one block here for the PMBR; on disks with a 512 byte
 201  202           * block size and 128 or fewer partitions, efi_first_u_lba
↓ open down ↓ 20 lines elided ↑ open up ↑
 222  223          int                     length;
 223  224          struct mboot            *mbr;
 224  225          struct ipart            *ipart;
 225  226          diskaddr_t              capacity;
 226  227          uint_t                  lbsize;
 227  228          int                     i;
 228  229  
 229  230          if (read_disk_info(fd, &capacity, &lbsize) != 0)
 230  231                  return (VT_ERROR);
 231  232  
 232      -        if ((mbr = calloc(lbsize, 1)) == NULL)
      233 +        if ((mbr = calloc(1, lbsize)) == NULL)
 233  234                  return (VT_ERROR);
 234  235  
 235  236          if ((ioctl(fd, DKIOCGMBOOT, (caddr_t)mbr)) == -1) {
 236  237                  free(mbr);
 237  238                  return (VT_ERROR);
 238  239          }
 239  240  
 240  241          if (mbr->signature != MBB_MAGIC) {
 241  242                  free(mbr);
 242  243                  return (VT_EINVAL);
↓ open down ↓ 6 lines elided ↑ open up ↑
 249  250                          break;
 250  251          }
 251  252          free(mbr);
 252  253          if (i == FD_NUMPART)
 253  254                  return (VT_EINVAL);
 254  255  
 255  256          /* figure out the number of entries that would fit into 16K */
 256  257          nparts = EFI_MIN_ARRAY_SIZE / sizeof (efi_gpe_t);
 257  258          length = (int) sizeof (struct dk_gpt) +
 258  259              (int) sizeof (struct dk_part) * (nparts - 1);
 259      -        if ((*vtoc = calloc(length, 1)) == NULL)
      260 +        if ((*vtoc = calloc(1, length)) == NULL)
 260  261                  return (VT_ERROR);
 261  262  
 262  263          (*vtoc)->efi_nparts = nparts;
 263  264          rval = efi_read(fd, *vtoc);
 264  265  
 265  266          if ((rval == VT_EINVAL) && (*vtoc)->efi_nparts > nparts) {
 266  267                  void *tmp;
 267  268                  length = (int) sizeof (struct dk_gpt) +
 268  269                      (int) sizeof (struct dk_part) *
 269  270                      ((*vtoc)->efi_nparts - 1);
↓ open down ↓ 146 lines elided ↑ open up ↑
 416  417          } else {
 417  418                  label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) +
 418  419                      disk_info.dki_lbsize;
 419  420                  if (label_len % disk_info.dki_lbsize) {
 420  421                          /* pad to physical sector size */
 421  422                          label_len += disk_info.dki_lbsize;
 422  423                          label_len &= ~(disk_info.dki_lbsize - 1);
 423  424                  }
 424  425          }
 425  426  
 426      -        if ((dk_ioc.dki_data = calloc(label_len, 1)) == NULL)
      427 +        if ((dk_ioc.dki_data = calloc(1, label_len)) == NULL)
 427  428                  return (VT_ERROR);
 428  429  
 429  430          dk_ioc.dki_length = disk_info.dki_lbsize;
 430  431          user_length = vtoc->efi_nparts;
 431  432          efi = dk_ioc.dki_data;
 432  433          if ((rval = check_label(fd, &dk_ioc)) == VT_EINVAL) {
 433  434                  /*
 434  435                   * No valid label here; try the alternate. Note that here
 435  436                   * we just read GPT header and save it into dk_ioc.data,
 436  437                   * Later, we will read GUID partition entry array if we
↓ open down ↓ 576 lines elided ↑ open up ↑
1013 1014           * the number of blocks occupied by GUID partition entry array
1014 1015           */
1015 1016          nblocks = dk_ioc.dki_length / vtoc->efi_lbasize - 1;
1016 1017  
1017 1018          /*
1018 1019           * Backup GPT header is located on the block after GUID
1019 1020           * partition entry array. Here, we calculate the address
1020 1021           * for backup GPT header.
1021 1022           */
1022 1023          lba_backup_gpt_hdr = vtoc->efi_last_u_lba + 1 + nblocks;
1023      -        if ((dk_ioc.dki_data = calloc(dk_ioc.dki_length, 1)) == NULL)
     1024 +        if ((dk_ioc.dki_data = calloc(1, dk_ioc.dki_length)) == NULL)
1024 1025                  return (VT_ERROR);
1025 1026  
1026 1027          efi = dk_ioc.dki_data;
1027 1028  
1028 1029          /* stuff user's input into EFI struct */
1029 1030          efi->efi_gpt_Signature = LE_64(EFI_SIGNATURE);
1030 1031          efi->efi_gpt_Revision = LE_32(vtoc->efi_version); /* 0x02000100 */
1031 1032          efi->efi_gpt_HeaderSize = LE_32(sizeof (struct efi_gpt));
1032 1033          efi->efi_gpt_Reserved1 = 0;
1033 1034          efi->efi_gpt_MyLBA = LE_64(1ULL);
↓ open down ↓ 301 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX