add some exception checking around some cases where vector types are used;

pull/86/head
Bryan Biedenkapp 1 year ago
parent 4617a817a1
commit cb335cffed

@ -305,7 +305,9 @@ bool AffiliationLookup::grantCh(uint32_t dstId, uint32_t srcId, uint32_t grantTi
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
uint32_t chNo = m_chLookup->getFirstRFChannel(); uint32_t chNo = m_chLookup->getFirstRFChannel();
m_chLookup->removeRFCh(chNo); if (!m_chLookup->removeRFCh(chNo)) {
return false;
}
m_grantChTable[dstId] = chNo; m_grantChTable[dstId] = chNo;
m_grantSrcIdTable[dstId] = srcId; m_grantSrcIdTable[dstId] = srcId;

@ -71,12 +71,18 @@ bool ChannelLookup::addRFCh(uint32_t chNo, bool force)
/* Helper to remove a RF channel. */ /* Helper to remove a RF channel. */
void ChannelLookup::removeRFCh(uint32_t chNo) bool ChannelLookup::removeRFCh(uint32_t chNo)
{ {
if (chNo == 0U) { if (chNo == 0U) {
return; return false;
} }
auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo); try {
m_rfChTable.erase(it); auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo);
m_rfChTable.erase(it);
} catch (...) {
return false;
}
return true;
} }

@ -206,8 +206,9 @@ namespace lookups
/** /**
* @brief Helper to remove a RF channel. * @brief Helper to remove a RF channel.
* @param chNo Channel Number. * @param chNo Channel Number.
* @returns bool True, if channel remove, otherwise false.
*/ */
void removeRFCh(uint32_t chNo); bool removeRFCh(uint32_t chNo);
/** /**
* @brief Helper to determine if there are any RF channels available.. * @brief Helper to determine if there are any RF channels available..
* @returns bool True, if any RF channels are available for use, otherwise false. * @returns bool True, if any RF channels are available for use, otherwise false.

@ -467,64 +467,69 @@ bool Socket::write(BufferVector& buffers, ssize_t* lenWritten) noexcept
continue; continue;
} }
// are we crypto wrapped? try {
if (m_isCryptoWrapped && m_presharedKey != nullptr) { // are we crypto wrapped?
uint32_t cryptedLen = length * sizeof(uint8_t); if (m_isCryptoWrapped && m_presharedKey != nullptr) {
uint8_t* cryptoBuffer = buffers[i]->buffer; uint32_t cryptedLen = length * sizeof(uint8_t);
uint8_t* cryptoBuffer = buffers[i]->buffer;
// do we need to pad the original buffer to be block aligned?
if (cryptedLen % crypto::AES::BLOCK_BYTES_LEN != 0) { // do we need to pad the original buffer to be block aligned?
uint32_t alignment = crypto::AES::BLOCK_BYTES_LEN - (cryptedLen % crypto::AES::BLOCK_BYTES_LEN); if (cryptedLen % crypto::AES::BLOCK_BYTES_LEN != 0) {
cryptedLen += alignment; uint32_t alignment = crypto::AES::BLOCK_BYTES_LEN - (cryptedLen % crypto::AES::BLOCK_BYTES_LEN);
cryptedLen += alignment;
// reallocate buffer and copy
cryptoBuffer = new uint8_t[cryptedLen]; // reallocate buffer and copy
::memset(cryptoBuffer, 0x00U, cryptedLen); cryptoBuffer = new uint8_t[cryptedLen];
::memcpy(cryptoBuffer, buffers.at(i)->buffer, length); ::memset(cryptoBuffer, 0x00U, cryptedLen);
} ::memcpy(cryptoBuffer, buffers.at(i)->buffer, length);
}
// encrypt
uint8_t* crypted = m_aes->encryptECB(cryptoBuffer, cryptedLen, m_presharedKey); // encrypt
delete[] cryptoBuffer; uint8_t* crypted = m_aes->encryptECB(cryptoBuffer, cryptedLen, m_presharedKey);
delete[] cryptoBuffer;
if (crypted == nullptr) {
--size; if (crypted == nullptr) {
continue; --size;
continue;
}
// Utils::dump(1U, "Socket::write() crypted", crypted, cryptedLen);
// finalize
UInt8Array __outBuf = std::make_unique<uint8_t[]>(cryptedLen + 2U);
uint8_t* out = __outBuf.get();
::memcpy(out + 2U, crypted, cryptedLen);
__SET_UINT16B(AES_WRAPPED_PCKT_MAGIC, out, 0U);
// cleanup buffers and replace with new
delete[] crypted;
//delete buffers[i]->buffer;
// this should never happen...
if (buffers[i] == nullptr) {
--size;
continue;
}
buffers[i]->buffer = new uint8_t[cryptedLen + 2U];
::memcpy(buffers[i]->buffer, out, cryptedLen + 2U);
buffers[i]->length = cryptedLen + 2U;
} }
// Utils::dump(1U, "Socket::write() crypted", crypted, cryptedLen); chunks[i].iov_len = buffers.at(i)->length;
chunks[i].iov_base = buffers.at(i)->buffer;
// finalize sent += buffers.at(i)->length;
UInt8Array __outBuf = std::make_unique<uint8_t[]>(cryptedLen + 2U);
uint8_t* out = __outBuf.get();
::memcpy(out + 2U, crypted, cryptedLen);
__SET_UINT16B(AES_WRAPPED_PCKT_MAGIC, out, 0U);
// cleanup buffers and replace with new
delete[] crypted;
//delete buffers[i]->buffer;
// this should never happen...
if (buffers[i] == nullptr) {
--size;
continue;
}
buffers[i]->buffer = new uint8_t[cryptedLen + 2U]; headers[i].msg_hdr.msg_name = (void*)&buffers.at(i)->address;
::memcpy(buffers[i]->buffer, out, cryptedLen + 2U); headers[i].msg_hdr.msg_namelen = buffers.at(i)->addrLen;
buffers[i]->length = cryptedLen + 2U; headers[i].msg_hdr.msg_iov = &chunks[i];
headers[i].msg_hdr.msg_iovlen = 1;
headers[i].msg_hdr.msg_control = 0;
headers[i].msg_hdr.msg_controllen = 0;
}
catch (...) {
--size;
} }
chunks[i].iov_len = buffers.at(i)->length;
chunks[i].iov_base = buffers.at(i)->buffer;
sent += buffers.at(i)->length;
headers[i].msg_hdr.msg_name = (void*)&buffers.at(i)->address;
headers[i].msg_hdr.msg_namelen = buffers.at(i)->addrLen;
headers[i].msg_hdr.msg_iov = &chunks[i];
headers[i].msg_hdr.msg_iovlen = 1;
headers[i].msg_hdr.msg_control = 0;
headers[i].msg_hdr.msg_controllen = 0;
} }
bool skip = false; bool skip = false;

Loading…
Cancel
Save

Powered by TurnKey Linux.