Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning removal. #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ApfsLib/AesXts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ void AesXts::Xor(uint8_t *out, const uint8_t *op1, const uint8_t *op2)
val64[1] = op1_64[1] ^ op2_64[1];
}

#ifdef __clang__
#pragma clang diagnostic ignored "-Wconditional-uninitialized"
#endif

void AesXts::MultiplyTweak(uint8_t* tweak)
{
uint8_t cin;
Expand All @@ -95,6 +99,6 @@ void AesXts::MultiplyTweak(uint8_t* tweak)
tweak[k] = (tweak[k] << 1) | cin;
cin = cout;
}
if (cout)
if (cout) // 2018-08 : wrongly reported uninitialized by clang
tweak[0] ^= 0x87;
}
4 changes: 2 additions & 2 deletions ApfsLib/ApfsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
int g_debug = 0;
bool g_lax = false;

ApfsContainer::ApfsContainer(Device &disk, uint64_t start, uint64_t len) :
ApfsContainer::ApfsContainer(Device &disk, uint64_t start/*, uint64_t len*/) :
m_disk(disk),
m_part_start(start),
m_part_len(len),
// m_part_len(len),
m_nodemap_vol(*this),
m_nidmap_bt(*this),
m_oldmgr_bt(*this),
Expand Down
6 changes: 3 additions & 3 deletions ApfsLib/ApfsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BlockDumper;
class ApfsContainer
{
public:
ApfsContainer(Device &disk, uint64_t start, uint64_t len);
ApfsContainer(Device &disk, uint64_t start/*, uint64_t len*/);
~ApfsContainer();

bool Init();
Expand All @@ -55,13 +55,13 @@ class ApfsContainer
private:
Device &m_disk;
const uint64_t m_part_start;
const uint64_t m_part_len;
// const uint64_t m_part_len; // Currently not used.

std::string m_passphrase;

APFS_NX_Superblock m_sb;

APFS_Block_8_5_Spaceman m_spaceman_hdr;
// APFS_Block_8_5_Spaceman m_spaceman_hdr;
// Block_8_11 ?

ApfsNodeMapperBTree m_nodemap_vol;
Expand Down
3 changes: 1 addition & 2 deletions ApfsLib/ApfsDir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ bool ApfsDir::ReadFile(void* data, uint64_t inode, uint64_t offs, size_t size)
uint8_t *bdata = reinterpret_cast<uint8_t *>(data);

size_t cur_size;
unsigned idx;

while (size > 0)
{
Expand Down Expand Up @@ -323,7 +322,7 @@ bool ApfsDir::ReadFile(void* data, uint64_t inode, uint64_t offs, size_t size)
return false;

// TODO: 12 is dependent on block size ...
idx = (offs - ext_key->logical_addr) >> 12;
auto idx = (offs - ext_key->logical_addr) >> 12;
// ext_val->size has a mysterious upper byte set. At least sometimes.
// Let us clear it.
uint64_t extent_size = ext_val->flags_length & 0x00FFFFFFFFFFFFFFULL;
Expand Down
8 changes: 3 additions & 5 deletions ApfsLib/BTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ void BTree::dump(BlockDumper& out)

void BTree::DumpTreeInternal(BlockDumper& out, const std::shared_ptr<BTreeNode> &node)
{
size_t k;
size_t cnt;
BTreeEntry e;
std::shared_ptr<BTreeNode> child;
uint64_t nodeid_child;
Expand All @@ -334,9 +332,9 @@ void BTree::DumpTreeInternal(BlockDumper& out, const std::shared_ptr<BTreeNode>

if (node->level() > 0)
{
cnt = node->entries_cnt();
auto cnt = node->entries_cnt();

for (k = 0; k < cnt; k++)
for (decltype(cnt) k = 0; k < cnt; k++)
{
node->GetEntry(e, k);

Expand Down Expand Up @@ -490,7 +488,7 @@ int BTree::FindBin(const std::shared_ptr<BTreeNode>& node, const void* key, size
int res;

BTreeEntry e;
int rc;
int rc = -1; // to silence warning about ch being used uninitialized.

if (cnt <= 0)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion ApfsLib/BlockDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void BlockDumper::DumpBTEntry_APFS_Root(const byte_t *key_data, size_t key_lengt
{
const APFS_Xattr_Val *attr = reinterpret_cast<const APFS_Xattr_Val *>(value_data);

assert(attr->size + 4 == value_length);
assert( decltype(value_length)(attr->size + 4) == value_length); // attr->size + 4 is promoted to int, giving a warning (comparison between signed and unsigned integer expressions). Hence the cast.

m_os << " => " << attr->type << " " << attr->size;

Expand Down
8 changes: 6 additions & 2 deletions ApfsLib/Crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <iostream>
#include <iomanip>

#include <limits.h>

#include "Endian.h"

union Rfc3394_Unit {
Expand All @@ -26,7 +28,8 @@ void Rfc3394_KeyWrap(uint8_t *crypto, const uint8_t *plain, size_t size, const u
uint64_t r[6];
int i;
int j;
int n = size / sizeof(uint64_t);
assert(size / sizeof(uint64_t) <= INT_MAX);
int n = int(size / sizeof(uint64_t));
uint64_t t;
const uint64_t *p = reinterpret_cast<const uint64_t *>(plain);
uint64_t *c = reinterpret_cast<uint64_t *>(crypto);
Expand Down Expand Up @@ -65,7 +68,8 @@ bool Rfc3394_KeyUnwrap(uint8_t *plain, const uint8_t *crypto, size_t size, const
uint64_t r[6];
int i;
int j;
int n = size / sizeof(uint64_t);
assert(size / sizeof(uint64_t) <= INT_MAX);
int n = int(size / sizeof(uint64_t));
uint64_t t;
const uint64_t *c = reinterpret_cast<const uint64_t *>(crypto);
uint64_t *p = reinterpret_cast<uint64_t *>(plain);
Expand Down
17 changes: 13 additions & 4 deletions ApfsLib/Decmpfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <cstring>
#include <cassert>

#include <limits.h>

#include "Decmpfs.h"
#include "Endian.h"

Expand Down Expand Up @@ -84,7 +86,7 @@ bool DecompressFile(ApfsDir &dir, uint64_t ino, std::vector<uint8_t> &decompress
const CompressionHeader *hdr = reinterpret_cast<const CompressionHeader *>(compressed.data());
const uint8_t *cdata = compressed.data() + sizeof(CompressionHeader);
size_t csize = compressed.size() - sizeof(CompressionHeader);
size_t decoded_bytes = 0;
size_t decoded_bytes;

#if 1 // Disable to get compressed data
if (g_debug & Dbg_Cmpfs)
Expand Down Expand Up @@ -147,7 +149,7 @@ bool DecompressFile(ApfsDir &dir, uint64_t ino, std::vector<uint8_t> &decompress
{
size_t src_offset = cmpf_rsrc->entry[k].off;
const uint8_t *src = cmpf_rsrc_base + src_offset;
size_t src_len = cmpf_rsrc->entry[k].size;
auto src_len = cmpf_rsrc->entry[k].size; //cmpf_rsrc->entry[k].size is uint32_t
uint8_t *dst = decompressed.data() + 0x10000 * k;
size_t expected_len = hdr->size - (0x10000 * k);
if (expected_len > 0x10000)
Expand All @@ -162,7 +164,8 @@ bool DecompressFile(ApfsDir &dir, uint64_t ino, std::vector<uint8_t> &decompress

if (src[0] == 0x78)
{
decoded_bytes = DecompressZLib(dst, 0x10000, src, src_len);
assert(src_len <= UINT_MAX);
decoded_bytes = DecompressZLib(dst, 0x10000, src, (unsigned int)src_len);
}
else if ((src[0] & 0x0F) == 0x0F)
{
Expand Down Expand Up @@ -236,7 +239,9 @@ bool DecompressFile(ApfsDir &dir, uint64_t ino, std::vector<uint8_t> &decompress
{
if (cdata[0] == 0x78)
{
decoded_bytes = DecompressZLib(decompressed.data(), decompressed.size(), cdata, csize);
assert(decompressed.size() <= UINT_MAX);
assert(csize <= UINT_MAX);
decoded_bytes = DecompressZLib(decompressed.data(), (unsigned int)decompressed.size(), cdata, (unsigned int)csize);
}
else if (cdata[0] == 0xFF) // cdata[0] & 0x0F == 0x0F ?
{
Expand All @@ -261,6 +266,10 @@ bool DecompressFile(ApfsDir &dir, uint64_t ino, std::vector<uint8_t> &decompress
decoded_bytes = DecompressLZVN(decompressed.data(), decompressed.size(), cdata, csize);
}
}
else
{
decoded_bytes = 0;
}

if (decoded_bytes != hdr->size)
{
Expand Down
10 changes: 8 additions & 2 deletions ApfsLib/DeviceDMG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ along with apfs-fuse. If not, see <http://www.gnu.org/licenses/>.
#include <vector>
#include <iostream>
#include <iomanip>
#include <assert.h>
#include <limits.h>

#include "DeviceDMG.h"
#include "Util.h"
Expand Down Expand Up @@ -435,10 +437,14 @@ bool DeviceDMG::Read(void * data, uint64_t offs, uint64_t len)
DecompressADC(sect.cache, sect.disk_length, compr_buf, sect.dmg_length);
break;
case 0x80000005:
DecompressZLib(sect.cache, sect.disk_length, compr_buf, sect.dmg_length);
assert(sect.disk_length <= UINT_MAX);
assert(sect.dmg_length <= UINT_MAX);
DecompressZLib(sect.cache, (unsigned int)sect.disk_length, compr_buf, (unsigned int)sect.dmg_length);
break;
case 0x80000006:
DecompressBZ2(sect.cache, sect.disk_length, compr_buf, sect.dmg_length);
assert(sect.disk_length <= UINT_MAX);
assert(sect.dmg_length <= UINT_MAX);
DecompressBZ2(sect.cache, (unsigned int)sect.disk_length, compr_buf, (unsigned int)sect.dmg_length);
break;
case 0x80000007:
DecompressLZFSE(sect.cache, sect.disk_length, compr_buf, sect.dmg_length);
Expand Down
11 changes: 8 additions & 3 deletions ApfsLib/KeyMgmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <iomanip>
#include <iostream>
#include <sstream>
#include <assert.h>
#include <limits.h>

#include "ApfsContainer.h"
#include "AesXts.h"
Expand Down Expand Up @@ -641,8 +643,8 @@ bool KeyManager::GetVolumeKey(uint8_t* vek, const apfs_uuid_t& volume_uuid, cons
uint64_t iv;
bool rc = false;

int cnt = recs_bag.GetKeyCnt();
int k;
auto cnt = recs_bag.GetKeyCnt();
decltype(cnt) k;

// Check all KEKs for any valid KEK.
for (k = 0; k < cnt; k++)
Expand All @@ -659,7 +661,8 @@ bool KeyManager::GetVolumeKey(uint8_t* vek, const apfs_uuid_t& volume_uuid, cons
if (!DecodeKEKBlob(kek_blob, kek_data))
continue;

PBKDF2_HMAC_SHA256(reinterpret_cast<const uint8_t *>(password), strlen(password), kek_blob.salt, sizeof(kek_blob.salt), kek_blob.iterations, dk, sizeof(dk));
assert(kek_blob.iterations <= INT_MAX);
PBKDF2_HMAC_SHA256(reinterpret_cast<const uint8_t *>(password), strlen(password), kek_blob.salt, sizeof(kek_blob.salt), int(kek_blob.iterations), dk, sizeof(dk));

switch (kek_blob.unk_82.unk_00)
{
Expand All @@ -673,6 +676,7 @@ bool KeyManager::GetVolumeKey(uint8_t* vek, const apfs_uuid_t& volume_uuid, cons
default:
std::cerr << "Unknown KEK key flags 82/00 = " << std::hex << kek_blob.unk_82.unk_00 << ". Please file a bug report." << std::endl;
rc = false;
iv = 0; // to silence warning about iv being used uninitialized.
break;
}

Expand Down Expand Up @@ -737,6 +741,7 @@ bool KeyManager::GetVolumeKey(uint8_t* vek, const apfs_uuid_t& volume_uuid, cons
// Unknown method.
std::cerr << "Unknown VEK key flags 82/00 = " << std::hex << vek_blob.unk_82.unk_00 << ". Please file a bug report." << std::endl;
rc = false;
iv = 0; // to silence the uninitialized warning
}

if (g_debug & Dbg_Crypto)
Expand Down
4 changes: 2 additions & 2 deletions ApfsLib/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ bool GetPassword(std::string &pw)
#endif
}

size_t DecompressZLib(uint8_t *dst, size_t dst_size, const uint8_t *src, size_t src_size)
size_t DecompressZLib(uint8_t *dst, unsigned int dst_size, const uint8_t *src, unsigned int src_size) // zstream can't take more than unsigned int for src and dst size
{
// size_t nwr = 0;
int ret;
Expand Down Expand Up @@ -503,7 +503,7 @@ size_t DecompressLZVN(uint8_t * dst, size_t dst_size, const uint8_t * src, size_
return static_cast<size_t>(state.dst - dst);
}

size_t DecompressBZ2(uint8_t * dst, size_t dst_size, const uint8_t * src, size_t src_size)
size_t DecompressBZ2(uint8_t * dst, unsigned int dst_size, const uint8_t * src, unsigned int src_size) // zstream can't take more than unsigned int for src and dst size
{
bz_stream strm;

Expand Down
4 changes: 2 additions & 2 deletions ApfsLib/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ int StrCmpUtf8NormalizedFolded(const char *s1, const char *s2, bool case_fold);

bool Utf8toUtf32(std::vector<char32_t> &str32, const char * str);

size_t DecompressZLib(uint8_t *dst, size_t dst_size, const uint8_t *src, size_t src_size);
size_t DecompressZLib(uint8_t *dst, unsigned int dst_size, const uint8_t *src, unsigned int src_size); // zstream can't take more than unsigned int for src and dst size
size_t DecompressADC(uint8_t *dst, size_t dst_size, const uint8_t *src, size_t src_size);
size_t DecompressLZVN(uint8_t *dst, size_t dst_size, const uint8_t *src, size_t src_size);
size_t DecompressBZ2(uint8_t *dst, size_t dst_size, const uint8_t *src, size_t src_size);
size_t DecompressBZ2(uint8_t *dst, unsigned int dst_size, const uint8_t *src, unsigned int src_size); // bz_stream can't take more than unsigned int for src and dst size
size_t DecompressLZFSE(uint8_t *dst, size_t dst_size, const uint8_t *src, size_t src_size);

bool GetPassword(std::string &pw);