1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-07-13 19:56:44 +08:00

Fix possible UB in mbedtls_asn1_write_raw_buffer()

This is mostly unrelated to other commits in this PR, except for the
fact that one of the added X.509 tests revealed that with UBSan.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2025-06-03 11:22:55 +02:00
parent 04fe95d95b
commit e51bde06da
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1,5 @@
Bugfix
* When calling mbedtls_asn1_write_raw_buffer() with NULL, 0 as the last two
arguments, undefined behaviour would be triggered, in the form of a call to
memcpy(..., NULL, 0). This was harmless in practice, but could trigger
complains from sanitizers or static analyzers.

View File

@ -90,7 +90,9 @@ int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start,
len = size;
(*p) -= len;
if (len != 0) {
memcpy(*p, buf, len);
}
return (int) len;
}