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

pull/86/head
Bryan Biedenkapp 11 months 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);
uint32_t chNo = m_chLookup->getFirstRFChannel();
m_chLookup->removeRFCh(chNo);
if (!m_chLookup->removeRFCh(chNo)) {
return false;
}
m_grantChTable[dstId] = chNo;
m_grantSrcIdTable[dstId] = srcId;

@ -71,12 +71,18 @@ bool ChannelLookup::addRFCh(uint32_t chNo, bool force)
/* Helper to remove a RF channel. */
void ChannelLookup::removeRFCh(uint32_t chNo)
bool ChannelLookup::removeRFCh(uint32_t chNo)
{
if (chNo == 0U) {
return;
return false;
}
auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo);
m_rfChTable.erase(it);
try {
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.
* @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..
* @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;
}
// are we crypto wrapped?
if (m_isCryptoWrapped && m_presharedKey != nullptr) {
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) {
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];
::memset(cryptoBuffer, 0x00U, cryptedLen);
::memcpy(cryptoBuffer, buffers.at(i)->buffer, length);
}
// encrypt
uint8_t* crypted = m_aes->encryptECB(cryptoBuffer, cryptedLen, m_presharedKey);
delete[] cryptoBuffer;
if (crypted == nullptr) {
--size;
continue;
try {
// are we crypto wrapped?
if (m_isCryptoWrapped && m_presharedKey != nullptr) {
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) {
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];
::memset(cryptoBuffer, 0x00U, cryptedLen);
::memcpy(cryptoBuffer, buffers.at(i)->buffer, length);
}
// encrypt
uint8_t* crypted = m_aes->encryptECB(cryptoBuffer, cryptedLen, m_presharedKey);
delete[] cryptoBuffer;
if (crypted == nullptr) {
--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);
// 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;
}
chunks[i].iov_len = buffers.at(i)->length;
chunks[i].iov_base = buffers.at(i)->buffer;
sent += buffers.at(i)->length;
buffers[i]->buffer = new uint8_t[cryptedLen + 2U];
::memcpy(buffers[i]->buffer, out, cryptedLen + 2U);
buffers[i]->length = cryptedLen + 2U;
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;
}
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;

Loading…
Cancel
Save

Powered by TurnKey Linux.