Print this page
3027 installgrub can segfault when encountering bogus data on disk

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/boot/common/mboot_extra.c
          +++ new/usr/src/cmd/boot/common/mboot_extra.c
↓ open down ↓ 107 lines elided ↑ open up ↑
 108  108   */
 109  109  bblk_einfo_t *
 110  110  find_einfo(char *extra)
 111  111  {
 112  112          bb_header_ext_t         *ext_header;
 113  113          bblk_einfo_t            *einfo;
 114  114          uint32_t                cksum;
 115  115  
 116  116          assert(extra != NULL);
 117  117  
 118      -        ext_header = (bb_header_ext_t *)extra;
 119      -        cksum = compute_checksum(extra + sizeof (bb_header_ext_t),
 120      -            ext_header->size);
 121      -        BOOT_DEBUG("Extended information header checksum is %x\n", cksum);
 122      -
 123      -        if (cksum != ext_header->checksum) {
 124      -                BOOT_DEBUG("Unable to find extended versioning information, "
 125      -                    "data looks corrupted\n");
 126      -                return (NULL);
 127      -        }
 128      -
 129  118          /*
 130  119           * Currently we only have one extra header so it must be encapsulating
 131  120           * the extended information structure.
 132  121           */
 133  122          einfo = (bblk_einfo_t *)(extra + sizeof (bb_header_ext_t));
 134  123          if (memcmp(einfo->magic, EINFO_MAGIC, EINFO_MAGIC_SIZE) != 0) {
 135  124                  BOOT_DEBUG("Unable to read stage2 extended versioning "
 136  125                      "information, wrong magic identifier\n");
 137  126                  BOOT_DEBUG("Found %s, expected %s\n", einfo->magic,
 138  127                      EINFO_MAGIC);
 139  128                  return (NULL);
 140  129          }
      130 +
      131 +        ext_header = (bb_header_ext_t *)extra;
      132 +        cksum = compute_checksum(extra + sizeof (bb_header_ext_t),
      133 +            ext_header->size);
      134 +        BOOT_DEBUG("Extended information header checksum is %x\n", cksum);
      135 +
      136 +        if (cksum != ext_header->checksum) {
      137 +                BOOT_DEBUG("Unable to find extended versioning information, "
      138 +                    "data looks corrupted\n");
      139 +                return (NULL);
      140 +        }
 141  141  
 142  142          return (einfo);
 143  143  }
 144  144  
 145  145  /*
 146  146   * Given a pointer to the extra area, add the extended information structure
 147  147   * encapsulated by a bb_header_ext_t structure.
 148  148   */
 149  149  void
 150  150  add_einfo(char *extra, char *updt_str, bblk_hs_t *hs, uint32_t avail_space)
↓ open down ↓ 30 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX