Skip to content

Commit 170c1fb

Browse files
authored
CoreFoundation: ensure that we do not overflow the dest
This `memcpy` could potentially overflow if the source was smaller than the destination. We now trim this to the minimum of the source and dest (similar to `strlcpy`).
1 parent d56e227 commit 170c1fb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ CF_CROSS_PLATFORM_EXPORT int _CFThreadGetName(char *buf, int length) {
16111611
char *buffer = calloc(szLength + 1, sizeof(char));
16121612
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, pszThreadDescription,
16131613
-1, buffer, szLength, NULL, NULL);
1614-
memcpy(buf, buffer, length - 1);
1614+
memcpy(buf, buffer, MIN(szLength, length - 1));
16151615
buf[MIN(szLength, length - 1)] = '\0';
16161616
free(buffer);
16171617
}

0 commit comments

Comments
 (0)