tftp
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user