fix: close remaining PR review gaps
CI / lint (pull_request) Successful in 32s
CI / sanitizers (undefined) (pull_request) Successful in 36s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / fuzz-build (pull_request) Successful in 13s
CI / coverage (pull_request) Successful in 31s
CI / build-and-test (pull_request) Successful in 1m15s
CI / valgrind (pull_request) Successful in 33s

This commit is contained in:
2026-08-15 20:38:04 +02:00
parent 7cffff0b8b
commit 059dc2ac75
4 changed files with 42 additions and 25 deletions
+24 -20
View File
@@ -336,13 +336,14 @@ bool file_save_to_disk(const char* root_directory, const File* file, const Confi
}
static File* receive_delta_file(int fd, const Config* config, const char* check_path,
void* old_data, unsigned long long old_size) {
void* old_data, unsigned long long old_size, bool* failed) {
if (!old_data)
return NULL;
DeltaSignature* sig = delta_signature_create(old_data, old_size, config->delta_block_size);
if (!sig) {
free(old_data);
*failed = true;
return NULL;
}
@@ -350,6 +351,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!sig_data) {
delta_signature_destroy(sig);
free(old_data);
*failed = true;
return NULL;
}
@@ -359,6 +361,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!sig_sent) {
delta_signature_destroy(sig);
free(old_data);
*failed = true;
return NULL;
}
@@ -366,6 +369,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!receive_status(fd, &resp)) {
delta_signature_destroy(sig);
free(old_data);
*failed = true;
return NULL;
}
@@ -374,7 +378,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!delta_data) {
delta_signature_destroy(sig);
free(old_data);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
@@ -385,7 +389,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!raw_delta) {
free(old_data);
delta_signature_destroy(sig);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
}
@@ -395,7 +399,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!delta) {
free(old_data);
delta_signature_destroy(sig);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
@@ -406,7 +410,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
if (!new_data) {
free(old_data);
delta_signature_destroy(sig);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
@@ -415,7 +419,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
free(new_data);
free(old_data);
delta_signature_destroy(sig);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
@@ -427,7 +431,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
free(new_data);
free(old_data);
delta_signature_destroy(sig);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
}
@@ -446,7 +450,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
File* file = file_create(check_path);
if (!file) {
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
@@ -455,7 +459,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
file->metadata = metadata_receive(fd, &meta_ok);
if (!meta_ok) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
}
@@ -463,7 +467,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
Data* file_data = receive_data(fd);
if (file_data == NULL) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
@@ -472,7 +476,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
data_destroy(file_data);
if (uncompressed == NULL) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
*failed = true;
return NULL;
}
file_data = uncompressed;
@@ -485,6 +489,7 @@ static File* receive_delta_file(int fd, const Config* config, const char* check_
delta_signature_destroy(sig);
free(old_data);
*failed = true;
return NULL;
}
@@ -492,7 +497,6 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
*skipped = false;
char* check_path = receive_str(fd);
if (check_path == NULL) {
send_status(fd, STATUS_ERROR);
return NULL;
}
@@ -502,19 +506,16 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
if (!receive_n_data(fd, &check_size, sizeof(check_size)) ||
!receive_n_data(fd, &check_mtime, sizeof(check_mtime))) {
free(check_path);
send_status(fd, STATUS_ERROR);
return NULL;
}
if (config->checksum && !receive_n_data(fd, &check_checksum, sizeof(check_checksum))) {
free(check_path);
send_status(fd, STATUS_ERROR);
return NULL;
}
if (has_path_traversal(check_path)) {
log_message(LOG_LEVEL_ERROR, "Path traversal detected: %s", check_path);
free(check_path);
send_status(fd, STATUS_ERROR);
return NULL;
}
@@ -582,13 +583,20 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
delta_should_attempt(old_size, check_size, config->delta_max_file_size);
if (try_delta) {
File* delta_file = receive_delta_file(fd, config, check_path, old_data, old_size);
bool delta_failed = false;
File* delta_file =
receive_delta_file(fd, config, check_path, old_data, old_size, &delta_failed);
old_data = NULL; /* receive_delta_file consumes the snapshot on every path */
if (delta_file) {
free(full_path);
free(check_path);
return delta_file;
}
if (delta_failed) {
free(full_path);
free(check_path);
return NULL;
}
free(old_data);
old_data = NULL;
try_delta = false;
@@ -606,7 +614,6 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
free(check_path);
free(full_path);
if (file == NULL) {
send_status(fd, STATUS_ERROR);
return NULL;
}
@@ -615,7 +622,6 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
file->metadata = metadata_receive(fd, &meta_ok);
if (!meta_ok) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
return NULL;
}
}
@@ -623,7 +629,6 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
Data* file_data = receive_data(fd);
if (file_data == NULL) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
return NULL;
}
@@ -632,7 +637,6 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
data_destroy(file_data);
if (uncompressed == NULL) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
return NULL;
}
file_data = uncompressed;