fix null termination in str_cat_str
fix check if not possible to fit string (did not check if null terminator fits
suggested by Lorenz
This commit is contained in:
2023-12-05 21:51:30 +01:00
parent 00d5f3a040
commit 5fd8bb3044

View File

@@ -28,10 +28,11 @@ static tftp_custom_file_t virt_file[] = {{.name = "index.txt", .data = NULL, .le
static int str_cat_str(char* dest, size_t dest_size, const char* src) {
size_t dest_len = strlen(dest);
size_t src_len = strlen(src);
if (dest_len + src_len > dest_size) {
if (dest_len + src_len >= dest_size) {
return -1;
}
memcpy(dest + dest_len, src, src_len);
dest[dest_len + src_len] = '\0';
return 0;
}