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 #88

Open
wants to merge 1 commit 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
1 change: 0 additions & 1 deletion ApfsLib/ApfsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ void ApfsContainer::dump(BlockDumper& bd)
bd.DumpNode(m_sm_data.data(), m_nx.nx_spaceman_oid);

uint64_t oid;
size_t k;

for (size_t k = 0; k < m_sm->sm_ip_bm_block_count; k++)
{
Expand Down
4 changes: 2 additions & 2 deletions ApfsLib/ApfsDir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ bool ApfsDir::GetAttribute(std::vector<uint8_t>& data, uint64_t inode, const cha
return false;

skey->hdr.obj_id_and_type = APFS_TYPE_ID(APFS_TYPE_XATTR, inode);
skey->name_len = static_cast<int16_t>(name_len);
skey->name_len = static_cast<uint16_t>(name_len); // safe cast : name_len is >= 0 && <= 0x400
memcpy(skey->name, name, skey->name_len);

rc = m_bt.Lookup(res, skey, sizeof(j_xattr_key_t) + skey->name_len, CompareStdDirKey, this, true);
Expand Down Expand Up @@ -693,7 +693,7 @@ bool ApfsDir::GetAttributeInfo(ApfsDir::XAttr& attr, uint64_t inode, const char*
return false;

skey->hdr.obj_id_and_type = APFS_TYPE_ID(APFS_TYPE_XATTR, inode);
skey->name_len = static_cast<int16_t>(name_len);
skey->name_len = static_cast<uint16_t>(name_len); // safe cast : name_len is >= 0 && <= 0x400
memcpy(skey->name, name, skey->name_len);

rc = m_bt.Lookup(res, skey, sizeof(j_xattr_key_t) + skey->name_len, CompareStdDirKey, this, true);
Expand Down
2 changes: 1 addition & 1 deletion ApfsLib/ApfsDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ApfsDir

uint64_t internal_flags;

uint64_t nchildren_nlink;
int32_t nchildren_nlink;

cp_key_class_t default_protection_class;
uint32_t write_generation_counter;
Expand Down
4 changes: 2 additions & 2 deletions ApfsLib/BTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void BTree::dump(BlockDumper& out)

void BTree::DumpTreeInternal(BlockDumper& out, const std::shared_ptr<BTreeNode> &node)
{
size_t k;
uint32_t k;
size_t cnt;
BTreeEntry e;
std::shared_ptr<BTreeNode> child;
Expand Down Expand Up @@ -491,7 +491,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
11 changes: 9 additions & 2 deletions ApfsLib/Decmpfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ bool DecompressFile(ApfsDir &dir, uint64_t ino, std::vector<uint8_t> &decompress

if (src[0] == 0x78)
{
decoded_bytes = DecompressZLib(dst, 0x10000, src, src_len);
#ifdef DEBUG
assert(src_len <= UINT_MAX);
#endif
decoded_bytes = DecompressZLib(dst, 0x10000, src, (unsigned int)src_len);
}
else if ((src[0] & 0x0F) == 0x0F)
{
Expand Down Expand Up @@ -236,7 +239,11 @@ 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);
#ifdef DEBUG
assert(decompressed.size() <= UINT_MAX);
assert(csize <= UINT_MAX);
#endif
decoded_bytes = DecompressZLib(decompressed.data(), (unsigned int)decompressed.size(), cdata, (unsigned int)csize);
}
else if (cdata[0] == 0xFF) // cdata[0] & 0x0F == 0x0F ?
{
Expand Down
6 changes: 3 additions & 3 deletions ApfsLib/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ inline uint16_t bswap_le(const uint16_t &x) { return x; }
inline uint32_t bswap_le(const uint32_t &x) { return x; }
inline uint64_t bswap_le(const uint64_t &x) { return x; }
// Swap to/from big endian.
inline int16_t bswap_be(const int16_t &x) { return bswap_16(x); }
inline int32_t bswap_be(const int32_t &x) { return bswap_32(x); }
inline int64_t bswap_be(const int64_t &x) { return bswap_64(x); }
inline int16_t bswap_be(const int16_t &x) { return (int16_t)bswap_16((uint16_t)x); }
inline int32_t bswap_be(const int32_t &x) { return (int32_t)bswap_32((uint32_t)x); }
inline int64_t bswap_be(const int64_t &x) { return (int64_t)bswap_64((uint64_t)x); }
inline uint16_t bswap_be(const uint16_t &x) { return bswap_16(x); }
inline uint32_t bswap_be(const uint32_t &x) { return bswap_32(x); }
inline uint64_t bswap_be(const uint64_t &x) { return bswap_64(x); }
Expand Down
21 changes: 14 additions & 7 deletions ApfsLib/KeyMgmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ bool KeyParser::GetTagAndLen(uint8_t & tag, size_t & len)
void KeyParser::GetRemaining(bagdata_t &data)
{
data.data = m_ptr;
data.size = m_end - m_ptr;
#ifdef DEBUG
assert(m_ptr >= m_end);
#endif
data.size = (size_t)(m_end - m_ptr);
}

Keybag::Keybag()
Expand Down Expand Up @@ -229,7 +232,7 @@ const keybag_entry_t * Keybag::GetKey(size_t nr)
{
kb = reinterpret_cast<const keybag_entry_t *>(ptr);

len = (kb->ke_keylen + sizeof(keybag_entry_t) + 0x0F) & ~0xF;
len = (kb->ke_keylen + sizeof(keybag_entry_t) + 0x0F) & ~0xFU;
ptr += len;
}

Expand Down Expand Up @@ -257,7 +260,7 @@ const keybag_entry_t * Keybag::FindKey(const apfs_uuid_t & uuid, uint16_t type)
if (memcmp(uuid, kb->ke_uuid, sizeof(apfs_uuid_t)) == 0 && kb->ke_tag == type)
return kb;

len = (kb->ke_keylen + sizeof(keybag_entry_t) + 0x0F) & ~0xF;
len = (kb->ke_keylen + sizeof(keybag_entry_t) + 0x0F) & ~0xFU;
ptr += len;
}

Expand Down Expand Up @@ -598,8 +601,8 @@ bool KeyManager::GetVolumeKey(uint8_t* vek, const apfs_uuid_t& volume_uuid, cons
const keybag_entry_t *ke_vek;
bagdata_t bd;

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 @@ -619,8 +622,10 @@ 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));
#ifdef DEBUG
assert(kek_blob.iterations <= INT_MAX);
#endif
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 @@ -634,6 +639,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 @@ -702,6 +708,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
6 changes: 3 additions & 3 deletions ApfsLib/PList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ void PListXmlParser::Base64Decode(std::vector<uint8_t>& bin, const char * str, s
ch = str[ip];

if (ch >= 'A' && ch <= 'Z')
dec = ch - 'A';
dec = (unsigned char)ch - 'A'; // safe cast, we know that ch >= 'A'
else if (ch >= 'a' && ch <= 'z')
dec = ch - 'a' + 0x1A;
dec = (unsigned char)ch - 'a' + 0x1A; // safe cast, we know that ch >= 'a'
else if (ch >= '0' && ch <= '9')
dec = ch - '0' + 0x34;
dec = (unsigned char)ch - '0' + 0x34; // safe cast, we know that ch >= '0'
else if (ch == '+')
dec = 0x3E;
else if (ch == '/')
Expand Down
40 changes: 21 additions & 19 deletions ApfsLib/Unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@

int normalizeJimdo(char32_t ch, char32_t *nfd, uint8_t *ccc)
{
constexpr int SBase = 0xAC00;
constexpr int LBase = 0x1100;
constexpr int VBase = 0x1161;
constexpr int TBase = 0x11A7;
constexpr uint32_t SBase = 0xAC00;
constexpr uint32_t LBase = 0x1100;
constexpr uint32_t VBase = 0x1161;
constexpr uint32_t TBase = 0x11A7;
// constexpr int LCount = 19;
constexpr int VCount = 21;
constexpr int TCount = 28;
constexpr int NCount = VCount * TCount;
constexpr unsigned int VCount = 21;
constexpr unsigned int TCount = 28;
constexpr unsigned int NCount = VCount * TCount;
// constexpr int SCount = LCount * NCount;

int SIndex = ch - SBase;
int LIndex = SIndex / NCount;
int VIndex = (SIndex % NCount) / TCount;
int TIndex = SIndex % TCount;
assert(ch > SBase);
uint32_t SIndex = ch - SBase;
uint32_t LIndex = SIndex / NCount;
uint32_t VIndex = (SIndex % NCount) / TCount;
uint32_t TIndex = SIndex % TCount;

nfd[0] = LBase + LIndex;
ccc[0] = 0;
Expand Down Expand Up @@ -81,7 +82,7 @@ int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t
if (hi_res == 0xAC00) // Naja, fast ... sollte funktionieren
return normalizeJimdo(ch, nfd, ccc);

mi_res = nf_trie_mid[((hi_res & 0xFFF) << 4) | ((ch_idx >> 4) & 0xF)];
mi_res = nf_trie_mid[((hi_res & 0xFFFU) << 4) | ((ch_idx >> 4) & 0xF)];

if (mi_res == 0xFFFF)
return -1;
Expand Down Expand Up @@ -111,7 +112,7 @@ int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t
return 1;
}

lo_res = nf_trie_lo[((mi_res & 0xFFF) << 4) | (ch_idx & 0xF)];
lo_res = nf_trie_lo[((mi_res & 0xFFFU) << 4) | (ch_idx & 0xF)];

if (lo_res == 0xFFFF)
return -1;
Expand Down Expand Up @@ -186,6 +187,7 @@ int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t
return 0;
break;
}
// seq_len can't be > 4.

for (cnt = 0; cnt < seq_len; cnt++)
{
Expand Down Expand Up @@ -219,7 +221,7 @@ int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t
continue;
}

mi_res = nf_trie_mid[((hi_res & 0xFFF) << 4) | ((ch_idx >> 4) & 0xF)];
mi_res = nf_trie_mid[((hi_res & 0xFFFU) << 4) | ((ch_idx >> 4) & 0xF)];

if (mi_res == 0 || ((mi_res & 0xFF00) == 0xAE00))
{
Expand All @@ -232,7 +234,7 @@ int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t
continue;
}

lo_res = nf_trie_lo[((mi_res & 0xFFF) << 4) | (ch_idx & 0xF)];
lo_res = nf_trie_lo[((mi_res & 0xFFFU) << 4) | (ch_idx & 0xF)];

if ((lo_res & 0xFF00) == 0xAD00)
ccc[cnt] = lo_res & 0xFF;
Expand All @@ -252,8 +254,8 @@ int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t
nfd[cnt - 1] = 0x3B9;
}
}

return cnt;
// here, cnt == seq_len, which is < 4. We can therefore assume that the cast to int safe :-)
return (int)cnt;
}

void CanonicalReorder(char32_t *nfd, uint8_t *ccc, size_t len)
Expand Down Expand Up @@ -313,10 +315,10 @@ bool NormalizeFoldString(std::vector<char32_t> &nfd, const std::vector<char32_t>
ch = in[k];
rc = normalizeOptFoldU32Char(ch, case_fold, nfd.data() + out_size, ccc.data() + out_size);

if (rc == -1)
if (rc < 0 )
return false;

out_size += rc;
out_size += (unsigned int)rc; // safe cast, as rc is >=0
}

nfd.resize(out_size);
Expand Down
8 changes: 4 additions & 4 deletions ApfsLib/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bool GetPassword(std::string &pw)
if (tcgetattr (fileno (stream), &told) != 0)
return false;
tnew = told;
tnew.c_lflag &= ~ECHO;
tnew.c_lflag &= ~((unsigned long)ECHO);
if (tcsetattr (fileno (stream), TCSAFLUSH, &tnew) != 0)
return false;

Expand All @@ -411,7 +411,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 @@ -453,7 +453,7 @@ size_t DecompressADC(uint8_t * dst, size_t dst_size, const uint8_t * src, size_t
size_t out_idx = 0;
uint8_t ctl;
int len;
int dist;
uint16_t dist;
int cnt;

for (;;)
Expand Down Expand Up @@ -519,7 +519,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 @@ -45,10 +45,10 @@ int StrCmpUtf8NormalizedFolded(const uint8_t *s1, const uint8_t *s2, bool case_f

bool Utf8toUtf32(std::vector<char32_t> &str32, const uint8_t * 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);
Expand Down