Ticket #9871: 0005-Chunk-Chunk-Fix-Null-pointer-argument-in-call-to-mem.patch

File 0005-Chunk-Chunk-Fix-Null-pointer-argument-in-call-to-mem.patch, 2.2 KB (added by mt, 7 years ago)

Patch

  • src/add-ons/kernel/file_systems/btrfs/Chunk.cpp

    From b65763850840f09444322c1b328e1f0bdcacd2e5 Mon Sep 17 00:00:00 2001
    From: Murai Takashi <tmurai01@gmail.com>
    Date: Sun, 14 Jul 2013 17:34:46 +0900
    Subject: [PATCH] Chunk::Chunk(), Fix Null pointer argument in call to memory copy function
    
    ---
     src/add-ons/kernel/file_systems/btrfs/Chunk.cpp |   29 +++++++++++++----------
     1 file changed, 16 insertions(+), 13 deletions(-)
    
    diff --git a/src/add-ons/kernel/file_systems/btrfs/Chunk.cpp b/src/add-ons/kernel/file_systems/btrfs/Chunk.cpp
    index 95d82a4..48cf078 100644
    a b Chunk::Chunk(struct btrfs_chunk* chunk, fsblock_t offset)  
    3030    fChunkOffset = offset;
    3131    fChunk = (struct btrfs_chunk*)malloc(sizeof(struct btrfs_chunk)
    3232        + chunk->StripeCount() * sizeof(struct btrfs_stripe));
    33     if (fChunk == NULL)
     33    if (fChunk == NULL) {
    3434        fInitStatus = B_NO_MEMORY;
    35     memcpy(fChunk, chunk, sizeof(struct btrfs_chunk)
    36         + chunk->StripeCount() * sizeof(struct btrfs_stripe));
    37 
    38     TRACE("chunk[0] length %" B_PRIu64 " owner %" B_PRIu64 " stripe_length %"
    39         B_PRIu64 " type %" B_PRIu64 " stripe_count %u sub_stripes %u "
    40         "sector_size %" B_PRIu32 "\n", chunk->Length(), chunk->Owner(),
    41         chunk->StripeLength(), chunk->Type(), chunk->StripeCount(),
    42         chunk->SubStripes(), chunk->SectorSize());
    43     for(int32 i = 0; i < chunk->StripeCount(); i++) {
    44         TRACE("chunk.stripe[%" B_PRId32 "].physical %" B_PRId64 " deviceid %"
    45             B_PRId64 "\n", i, chunk->stripes[i].Offset(),
    46             chunk->stripes[i].DeviceID());
     35        /* Need TRACE() here? */
     36    } else {
     37        memcpy(fChunk, chunk, sizeof(struct btrfs_chunk)
     38            + chunk->StripeCount() * sizeof(struct btrfs_stripe));
     39
     40        TRACE("chunk[0] length %" B_PRIu64 " owner %" B_PRIu64 " stripe_length %"
     41            B_PRIu64 " type %" B_PRIu64 " stripe_count %u sub_stripes %u "
     42            "sector_size %" B_PRIu32 "\n", chunk->Length(), chunk->Owner(),
     43            chunk->StripeLength(), chunk->Type(), chunk->StripeCount(),
     44            chunk->SubStripes(), chunk->SectorSize());
     45        for(int32 i = 0; i < chunk->StripeCount(); i++) {
     46            TRACE("chunk.stripe[%" B_PRId32 "].physical %" B_PRId64 " deviceid %"
     47                B_PRId64 "\n", i, chunk->stripes[i].Offset(),
     48                chunk->stripes[i].DeviceID());
     49        }
    4750    }
    4851}
    4952