Skip to content
Closed
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
14 changes: 12 additions & 2 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10057,7 +10057,11 @@ static int PreparePacket(WOLFSSH* ssh, word32 payloadSz)
word32 packetSz, outputSz;
byte paddingSz;

paddingSz = ssh->blockSz * 2;
/* Ensure enough space for worst-case padding scenario:
* - At least MIN_PAD_LENGTH (4)
* - Plus potentially another blockSz for alignment
* This gives us a safe upper bound */
paddingSz = ssh->blockSz * 3;
packetSz = PAD_LENGTH_SZ + payloadSz + paddingSz;
outputSz = LENGTH_SZ + packetSz + ssh->macSz;

Expand Down Expand Up @@ -10109,8 +10113,14 @@ static int BundlePacket(WOLFSSH* ssh)

/* Add the padding */
WLOG(WS_LOG_DEBUG, "BP: paddingSz = %u", paddingSz);
if (ssh->encryptId == ID_NONE)
/* Verify we have enough space for padding */
if (idx + paddingSz > ssh->outputBuffer.bufferSz) {
ret = WS_BUFFER_E;
WLOG(WS_LOG_DEBUG, "BP: buffer too small for padding");
}
else if (ssh->encryptId == ID_NONE) {
WMEMSET(output + idx, 0, paddingSz);
}
else if (wc_RNG_GenerateBlock(ssh->rng, output + idx, paddingSz) < 0) {
ret = WS_CRYPTO_FAILED;
WLOG(WS_LOG_DEBUG, "BP: failed to add padding");
Expand Down
Loading