Changeset 493b881 in mainline


Ignore:
Timestamp:
2013-07-30T11:54:19Z (11 years ago)
Author:
Dominik Taborsky (AT DOT) <brembyseznamcz>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0435fe41
Parents:
2b55edb
Message:

libgpt correctly checks boundaries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gpt/libgpt.c

    r2b55edb r493b881  
    364364        label->gpt->header->fillries = host2uint32_t_le(fillries);
    365365        uint64_t arr_blocks = (fillries * sizeof(gpt_entry_t)) / b_size;
    366         label->gpt->header->first_usable_lba = host2uint64_t_le(arr_blocks + 1);
    367         uint64_t first_lba = n_blocks - arr_blocks - 2;
    368         label->gpt->header->last_usable_lba = host2uint64_t_le(first_lba);
     366        uint64_t gpt_space = arr_blocks + GPT_HDR_BS + 1; /* +1 for Protective MBR */
     367        label->gpt->header->first_usable_lba = host2uint64_t_le(gpt_space);
     368        label->gpt->header->last_usable_lba = host2uint64_t_le(n_blocks - gpt_space - 1);
    369369       
    370370        /* Perform checks */
     
    373373                        continue;
    374374               
    375                 if (!check_encaps(p, n_blocks, first_lba)) {
     375                if (!check_encaps(p, n_blocks, gpt_space)) {
    376376                        rc = ERANGE;
     377                        printf("encaps with: %llu, %llu, %llu\n", n_blocks, gpt_space, gpt_get_end_lba(p));
    377378                        goto fail;
    378379                }
     
    384385                        if (gpt_get_part_type(p) != GPT_PTE_UNUSED) {
    385386                                if (check_overlap(p, q)) {
     387                                        printf("overlap with: %llu, %llu\n", gpt_get_start_lba(p), gpt_get_start_lba(q));
    386388                                        rc = ERANGE;
    387389                                        goto fail;
     
    838840static bool check_overlap(gpt_part_t * p1, gpt_part_t * p2)
    839841{
    840         if (gpt_get_start_lba(p1) < gpt_get_start_lba(p2) && gpt_get_end_lba(p1) <= gpt_get_start_lba(p2)) {
     842        if (gpt_get_start_lba(p1) < gpt_get_start_lba(p2) && gpt_get_end_lba(p1) < gpt_get_start_lba(p2)) {
    841843                return false;
    842         } else if (gpt_get_start_lba(p1) > gpt_get_start_lba(p2) && gpt_get_end_lba(p2) <= gpt_get_start_lba(p1)) {
     844        } else if (gpt_get_start_lba(p1) > gpt_get_start_lba(p2) && gpt_get_end_lba(p2) < gpt_get_start_lba(p1)) {
    843845                return false;
    844846        }
     
    849851static bool check_encaps(gpt_part_t *p, uint64_t n_blocks, uint64_t first_lba)
    850852{
    851         uint64_t start = uint64_t_le2host(p->start_lba);
    852         uint64_t end = uint64_t_le2host(p->end_lba);
    853        
    854         if (start >= first_lba && end < n_blocks - first_lba)
     853        /*
     854         * We allow "<=" in the second expression because it lacks MBR so
     855         * it's by 1 block smaller.
     856         */
     857        if (gpt_get_start_lba(p) >= first_lba && gpt_get_end_lba(p) <= n_blocks - first_lba)
    855858                return true;
    856859       
Note: See TracChangeset for help on using the changeset viewer.