ICU-21118 check that dst and src are not null in uprv_memcpy

See #1489
This commit is contained in:
Erik Torres Aguilar 2020-12-09 19:35:39 +00:00 committed by Erik Torres
parent 3d62b74392
commit 17f725fe0d
2 changed files with 17 additions and 3 deletions

View file

@ -31,14 +31,25 @@
#include <stddef.h>
#include <string.h>
#include "unicode/localpointer.h"
#include "uassert.h"
#if U_DEBUG && defined(UPRV_MALLOC_COUNT)
#include <stdio.h>
#endif
#define uprv_memcpy(dst, src, size) U_STANDARD_CPP_NAMESPACE memcpy(dst, src, size)
#define uprv_memmove(dst, src, size) U_STANDARD_CPP_NAMESPACE memmove(dst, src, size)
#define uprv_memcpy(dst, src, size) UPRV_BLOCK_MACRO_BEGIN { \
U_ASSERT(dst != NULL); \
U_ASSERT(src != NULL); \
U_STANDARD_CPP_NAMESPACE memcpy(dst, src, size); \
} UPRV_BLOCK_MACRO_END
#define uprv_memmove(dst, src, size) UPRV_BLOCK_MACRO_BEGIN { \
U_ASSERT(dst != NULL); \
U_ASSERT(src != NULL); \
U_STANDARD_CPP_NAMESPACE memmove(dst, src, size); \
} UPRV_BLOCK_MACRO_END
/**
* \def UPRV_LENGTHOF

View file

@ -2047,7 +2047,10 @@ ultag_parse(const char* tag, int32_t tagLen, int32_t* parsedLen, UErrorCode* sta
*status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
uprv_memcpy(tagBuf, tag, tagLen);
if (tagLen > 0) {
uprv_memcpy(tagBuf, tag, tagLen);
}
*(tagBuf + tagLen) = 0;
/* create a ULanguageTag */