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 <[email protected]>
This commit is contained in:
Manuel Pégourié-Gonnard
2025-06-03 11:23:19 +02:00
parent 04fe95d95b
commit e51bde06da
2 changed files with 8 additions and 1 deletions
+5
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.
+3 -1
View File
@@ -90,7 +90,9 @@ int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start,
len = size;
(*p) -= len;
memcpy(*p, buf, len);
if (len != 0) {
memcpy(*p, buf, len);
}
return (int) len;
}