fix: ensure null terminator is appended to string copy in timerGetSource
The timerGetSource function allocates a buffer and copies the source string using strncpy, which does not guarantee null termination when the source length equals the buffer size. This change explicitly sets the final character to '\0' to prevent potential buffer over-reads or undefined behavior when the returned string is used by callers.
This commit is contained in:
@@ -63,6 +63,7 @@ char* timerGetSource()
|
||||
size_t length = strlen(timerLibSource);
|
||||
char* copy = (char*)malloc(length + 1);
|
||||
strncpy(copy, timerLibSource, length);
|
||||
copy[length] = '\0';
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user