mirror of
https://github.com/strongswan/strongswan.git
synced 2025-12-01 00:00:31 -05:00
Check that chunk fits into sequence when converting
This commit is contained in:
parent
3360bad910
commit
d2371b728c
@ -14,6 +14,8 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <utils/debug.h>
|
||||||
|
|
||||||
#include "tkm_utils.h"
|
#include "tkm_utils.h"
|
||||||
|
|
||||||
/* Generic variable-length sequence */
|
/* Generic variable-length sequence */
|
||||||
@ -33,8 +35,18 @@ void sequence_to_chunk(const byte_t * const first, const uint32_t len,
|
|||||||
void chunk_to_sequence(const chunk_t * const chunk, void *sequence,
|
void chunk_to_sequence(const chunk_t * const chunk, void *sequence,
|
||||||
const uint32_t typelen)
|
const uint32_t typelen)
|
||||||
{
|
{
|
||||||
|
const uint32_t seqlenmax = typelen - sizeof(uint32_t);
|
||||||
memset(sequence, 0, typelen);
|
memset(sequence, 0, typelen);
|
||||||
sequence_type *seq = sequence;
|
sequence_type *seq = sequence;
|
||||||
seq->size = chunk->len;
|
if (chunk->len > seqlenmax)
|
||||||
|
{
|
||||||
|
DBG1(DBG_LIB, "chunk too large to fit into sequence %d > %d, limiting"
|
||||||
|
" to %d bytes", chunk->len, seqlenmax, seqlenmax);
|
||||||
|
seq->size = seqlenmax;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
seq->size = chunk->len;
|
||||||
|
}
|
||||||
memcpy(seq->data, chunk->ptr, seq->size);
|
memcpy(seq->data, chunk->ptr, seq->size);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user