Compare commits

..

13 Commits

Author SHA1 Message Date
TapTap bd2af8071a fix: address review findings — sendfile EINTR, path traversal check
CI / lint (pull_request) Successful in 9s
CI / sanitizers (address) (pull_request) Successful in 16s
CI / sanitizers (undefined) (pull_request) Successful in 16s
CI / coverage (pull_request) Successful in 11s
CI / fuzz-build (pull_request) Successful in 13s
CI / valgrind (pull_request) Successful in 12s
CI / build-and-test (pull_request) Successful in 55s
2026-07-21 14:17:51 +02:00
TapTap b20e39012e fix: clang-format compliance
CI / lint (pull_request) Successful in 9s
CI / sanitizers (address) (pull_request) Successful in 14s
CI / sanitizers (undefined) (pull_request) Successful in 16s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 9s
CI / valgrind (pull_request) Successful in 13s
CI / build-and-test (pull_request) Successful in 53s
2026-07-20 22:01:00 +02:00
TapTap 58a83193ff fix: test quality — cppcheck suppressions, TLS test addresses, log test isolation
CI / lint (pull_request) Failing after 2s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 21:27:37 +02:00
TapTap 5b5c7b2a7e fix: security issues — path traversal, TLS hostname, SUID, OOM, stack overflow
CI / lint (pull_request) Failing after 3s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 21:26:11 +02:00
TapTap 88ad77e397 fix: memory safety — malloc NULL checks, strcpy→memcpy, str_dup NULL check, remove unused include
CI / lint (pull_request) Failing after 3s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 21:26:01 +02:00
TapTap eb6034044b fix: accept_loop race condition, auto-detect valgrind, cppcheck suppressions
CI / lint (pull_request) Successful in 9s
CI / sanitizers (undefined) (pull_request) Successful in 16s
CI / sanitizers (address) (pull_request) Successful in 16s
CI / coverage (pull_request) Successful in 10s
CI / fuzz-build (pull_request) Successful in 13s
CI / valgrind (pull_request) Successful in 12s
CI / build-and-test (pull_request) Successful in 53s
2026-07-20 21:09:10 +02:00
TapTap 432e9a3ed4 ci: re-trigger after cppcheck fixes
CI / lint (pull_request) Failing after 9s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 20:41:22 +02:00
TapTap 2265f93a18 fix: cppcheck — remove redundant free before _exit in transport_ssh.c
CI / lint (pull_request) Failing after 9s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 20:39:42 +02:00
TapTap b816437777 ci: re-trigger after fixes
CI / lint (pull_request) Failing after 9s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 20:28:21 +02:00
TapTap c5d8a4e2ea ci: re-trigger after review fixes
CI / lint (pull_request) Failing after 9s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 20:11:28 +02:00
TapTap 0d57f3c812 fix: review fixes — getsockname, memcpy, clang-format
CI / lint (pull_request) Failing after 9s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 19:52:48 +02:00
TapTap 81739b79c5 ci: trigger CI on PR
CI / lint (pull_request) Failing after 2s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 19:48:35 +02:00
TapTap a2bcda1fcf fix: initialize ssl_ctx in server_create, update tests for sockaddr_storage API
CI / lint (pull_request) Failing after 2s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
2026-07-20 19:39:13 +02:00
24 changed files with 112 additions and 166 deletions
View File
View File
+2 -11
View File
@@ -56,8 +56,6 @@ static void print_usage(void) {
printf(" --key <path> TLS private key file (PEM)\n");
printf(" --ca <path> TLS CA certificate file (PEM)\n");
printf(" --partial Keep partial files on interrupted transfer\n");
printf(" --fastsync-server-path <path>\n");
printf(" Path to fastsync-server on remote (default: fastsync-server)\n");
printf(" --help Show this help\n");
printf(" -V, --version Show version and exit\n");
}
@@ -72,14 +70,10 @@ int main(int argc, char* argv[]) {
save_to_disk = true;
}
int exit_code = 0;
bool config_owned_by_pipeline = false;
Config* config = config_create(str_dup(PROTOCOL_VERSION), NULL, NULL, save_to_disk, false, false,
false, false, 5, false, 0);
if (config == NULL) {
exit_code = 1;
goto cleanup;
}
int exit_code = 0;
bool config_owned_by_pipeline = false;
int positional_args[2];
int positional_count = 0;
@@ -226,9 +220,6 @@ int main(int argc, char* argv[]) {
config->tls_ca = str_dup(argv[++i]);
} else if (strcmp(argv[i], "--partial") == 0) {
config->partial = true;
} else if (strcmp(argv[i], "--fastsync-server-path") == 0 && i + 1 < argc) {
free(config->fastsync_server_path);
config->fastsync_server_path = str_dup(argv[++i]);
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
set_log_level(LOG_LEVEL_DEBUG);
} else if (argv[i][0] == '-') {
+2 -4
View File
@@ -228,8 +228,7 @@ static int send_chunks_multithreaded(void* pipeline_context) {
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
return 1;
}
client = client_connect_ssh(context->config->ssh_destination, context->config->ssh_port,
context->config->fastsync_server_path);
client = client_connect_ssh(context->config->ssh_destination, context->config->ssh_port);
} else if (context->config->use_tls) {
client = client_create();
if (!client || !client_connect_tls(client, context->config->server_host,
@@ -386,8 +385,7 @@ int send_files(Config* config) {
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
return 1;
}
client =
client_connect_ssh(config->ssh_destination, config->ssh_port, config->fastsync_server_path);
client = client_connect_ssh(config->ssh_destination, config->ssh_port);
if (!client)
return 1;
} else if (config->use_tls) {
+1 -13
View File
@@ -91,19 +91,7 @@ DirectoryScanner* directory_scanner_create_full(char* root_directory, bool use_m
scanner->max_size = max_size;
scanner->min_size = min_size;
scanner->follow_symlinks = follow_symlinks;
char* root_copy = str_dup(root_directory);
if (root_copy == NULL) {
for (int i = 0; i < scanner->include_count; i++)
free(scanner->include_patterns[i]);
free(scanner->include_patterns);
for (int i = 0; i < scanner->exclude_count; i++)
free(scanner->exclude_patterns[i]);
free(scanner->exclude_patterns);
queue_destroy(scanner->directories);
free(scanner);
return NULL;
}
queue_enqueue(scanner->directories, root_copy);
queue_enqueue(scanner->directories, str_dup(root_directory));
return scanner;
}
+4 -5
View File
@@ -23,8 +23,6 @@ static bool is_excluded(const char* path, const Config* config) {
char* path_dup = str_dup(path);
if (!path_dup)
return false;
/* basename(3) may return a pointer into path_dup or a static buffer;
* either way we free path_dup, not fname. */
char* fname = basename(path_dup);
// Check exclude patterns
@@ -247,9 +245,10 @@ int main(int argc, char* argv[]) {
server_listen(g_server, handler);
}
/* Graceful shutdown: delete the server */
if (g_server_cleanup_requested)
/* Graceful shutdown: if a signal requested cleanup, delete the server */
if (g_server_cleanup_requested) {
log_message(LOG_LEVEL_INFO, "Shutdown requested, cleaning up");
server_delete(&g_server);
server_delete(&g_server);
}
return 0;
}
+8 -15
View File
@@ -34,7 +34,6 @@ Config* config_create(char* version, char* send_directory, char* receive_directo
config->ssh_port = 22;
config->transport = TRANSPORT_TCP;
config->ssh_destination = NULL;
config->fastsync_server_path = NULL;
config->exclude_patterns = NULL;
config->exclude_count = 0;
config->include_patterns = NULL;
@@ -83,13 +82,10 @@ void config_parse_ssh_dest(Config* config) {
}
void config_delete(Config* config) {
if (config == NULL)
return;
free(config->version);
free(config->send_directory);
free(config->receive_root_directory);
free(config->ssh_destination);
free(config->fastsync_server_path);
for (int i = 0; i < config->exclude_count; i++)
free(config->exclude_patterns[i]);
free(config->exclude_patterns);
@@ -240,7 +236,6 @@ Config* config_receive(int file_descriptor) {
config->ssh_port = 22;
config->transport = TRANSPORT_TCP;
config->ssh_destination = NULL;
config->fastsync_server_path = NULL;
config->exclude_patterns = NULL;
config->exclude_count = 0;
config->include_patterns = NULL;
@@ -265,6 +260,10 @@ Config* config_receive(int file_descriptor) {
MAX_PATTERN_COUNT);
goto error;
}
if ((size_t)ec > SIZE_MAX / sizeof(char*)) {
log_message(LOG_LEVEL_ERROR, "Exclude pattern count %d would cause integer overflow", ec);
goto error;
}
config->exclude_count = ec;
if (ec > 0) {
config->exclude_patterns = malloc((size_t)ec * sizeof(char*));
@@ -294,6 +293,10 @@ Config* config_receive(int file_descriptor) {
MAX_PATTERN_COUNT);
goto error;
}
if ((size_t)ic > SIZE_MAX / sizeof(char*)) {
log_message(LOG_LEVEL_ERROR, "Include pattern count %d would cause integer overflow", ic);
goto error;
}
config->include_count = ic;
if (ic > 0) {
config->include_patterns = malloc((size_t)ic * sizeof(char*));
@@ -337,16 +340,6 @@ error:
free(config->version);
free(config->send_directory);
free(config->receive_root_directory);
for (int i = 0; i < config->exclude_count; i++)
free(config->exclude_patterns[i]);
free(config->exclude_patterns);
for (int i = 0; i < config->include_count; i++)
free(config->include_patterns[i]);
free(config->include_patterns);
free(config->tls_cert);
free(config->tls_key);
free(config->tls_ca);
free(config->ssh_destination);
free(config->server_host);
free(config);
return NULL;
+1 -2
View File
@@ -24,7 +24,6 @@ typedef struct Config {
int ssh_port;
TransportType transport;
char* ssh_destination;
char* fastsync_server_path;
char** exclude_patterns;
int exclude_count;
char** include_patterns;
@@ -45,7 +44,7 @@ typedef struct Config {
bool partial;
} Config;
#define PROTOCOL_VERSION "2.0.0"
#define PROTOCOL_VERSION "1.3.0"
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
Config* config_create(char* version, char* send_directory, char* receive_directory,
+1 -1
View File
@@ -1,6 +1,6 @@
#include "data.h"
#include "log.h"
#include <stdlib.h>
#include "stdlib.h"
Data* data_create_empty(size_t data_size) {
/* malloc(0) is UB; allocate at least 1 byte but preserve requested size */
+22 -18
View File
@@ -3,7 +3,6 @@
#include <fcntl.h>
#include <libgen.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -110,9 +109,6 @@ bool file_load_data(File* file) {
size_t bytes_read = file_content_to_buffer(file);
if (bytes_read != file->data->size) {
log_message(LOG_LEVEL_ERROR, "Did not read expected amount of bytes from file");
free(file->data->data);
file->data->data = NULL;
file->data->size = 0;
return false;
}
return true;
@@ -144,13 +140,11 @@ static bool file_send_streaming(File* file, int file_descriptor) {
if (ferror(fp)) {
perror("Read error during streaming");
}
send_status(file_descriptor, STATUS_ERROR);
free(buf);
fclose(fp);
return false;
}
if (!send_n_data(file_descriptor, buf, nread)) {
send_status(file_descriptor, STATUS_ERROR);
free(buf);
fclose(fp);
return false;
@@ -206,10 +200,25 @@ bool file_send_single_calls(File* file, int file_descriptor, bool use_metadata,
return true;
}
static bool has_path_traversal(const char* path) {
// Check if ".." appears as a path component — at start, end, or between '/'
const char* p = path;
while ((p = strstr(p, "..")) != NULL) {
bool at_start = (p == path);
bool after_slash = (p > path && p[-1] == '/');
bool at_end = (p[2] == '\0');
bool before_slash = (p[2] == '/');
if ((at_start || after_slash) && (at_end || before_slash))
return true;
p += 2;
}
return false;
}
bool file_save_to_disk(const char* root_directory, File* file) {
if (file->type == FILE_TYPE_SYMLINK && file->link_target) {
// Validate link_target — reject absolute paths or traversal
if (file->link_target[0] == '/' || strstr(file->link_target, "..") != NULL) {
if (file->link_target[0] == '/' || has_path_traversal(file->link_target)) {
log_message(LOG_LEVEL_ERROR, "Path traversal blocked in symlink target: %s",
file->link_target);
return false;
@@ -217,7 +226,7 @@ bool file_save_to_disk(const char* root_directory, File* file) {
char* disk_path = path_cat((char*)root_directory, file->path);
if (disk_path == NULL)
return false;
if (strstr(disk_path, "..") != NULL) {
if (has_path_traversal(disk_path)) {
log_message(LOG_LEVEL_ERROR, "Path traversal blocked: %s", disk_path);
free(disk_path);
return false;
@@ -233,7 +242,7 @@ bool file_save_to_disk(const char* root_directory, File* file) {
char* disk_path = path_cat((char*)root_directory, file->path);
if (disk_path == NULL)
return false;
if (strstr(disk_path, "..") != NULL) {
if (has_path_traversal(disk_path)) {
log_message(LOG_LEVEL_ERROR, "Path traversal blocked: %s", disk_path);
free(disk_path);
return false;
@@ -302,21 +311,17 @@ static bool receive_and_assign_metadata(int fd, const Config* config, File* file
static File* receive_delta_file(int fd, const Config* config, const char* check_path,
void* old_data, unsigned long long old_size) {
if (!old_data) {
send_status(fd, STATUS_ERROR);
if (!old_data)
return NULL;
}
DeltaSignature* sig = delta_signature_create(old_data, old_size, config->delta_block_size);
if (!sig) {
send_status(fd, STATUS_ERROR);
free(old_data);
return NULL;
}
Data* sig_data = delta_signature_serialize(sig);
if (!sig_data) {
send_status(fd, STATUS_ERROR);
delta_signature_destroy(sig);
free(old_data);
return NULL;
@@ -528,6 +533,7 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
if (!receive_and_assign_metadata(fd, config, file))
return NULL;
// Read file type indicator
int file_type;
if (!receive_int(fd, &file_type)) {
file_destroy(file);
@@ -614,6 +620,7 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
if (use_metadata && !metadata_send(file_descriptor, file->metadata))
return false;
// Send file type indicator
int ft = (int)file->type;
if (!send_int(file_descriptor, ft))
return false;
@@ -632,10 +639,7 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
off_t offset = 0;
while ((unsigned long long)offset < file_size) {
size_t send_count = (size_t)(file_size - (unsigned long long)offset);
if ((unsigned long long)send_count != file_size - (unsigned long long)offset)
send_count = SIZE_MAX;
ssize_t sent = sendfile(file_descriptor, fd, &offset, send_count);
ssize_t sent = sendfile(file_descriptor, fd, &offset, file_size - offset);
if (sent == -1) {
if (errno == EINTR)
continue;
+1 -4
View File
@@ -14,10 +14,7 @@ void log_message(LogLevel log_level, const char* format, ...) {
if (log_level < current_log_level)
return;
time_t now = time(NULL);
struct tm result_buf;
const struct tm* t = localtime_r(&now, &result_buf);
if (t == NULL)
return;
const struct tm* t = localtime(&now);
fprintf(stderr, "%04d-%02d-%02d %02d:%02d:%02d [%s]: ", t->tm_year + 1900, t->tm_mon + 1,
t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, log_level_strings[log_level]);
-13
View File
@@ -11,19 +11,6 @@
#include <time.h>
#include <unistd.h>
/*
* Wire format serialization (protocol version 2.0.0+):
* All metadata fields are serialized as fixed-width integers (int32_t / int64_t)
* to ensure cross-platform binary compatiblity. See metadata.h for the
* exact wire layout.
*
* Compile-time assertions verify that the native platform types fit within
* the chosen fixed-width representations.
*/
typedef char static_assert_mode_t_fits[(sizeof(mode_t) <= sizeof(int32_t)) ? 1 : -1];
typedef char static_assert_uid_t_fits[(sizeof(uid_t) <= sizeof(int32_t)) ? 1 : -1];
typedef char static_assert_gid_t_fits[(sizeof(gid_t) <= sizeof(int32_t)) ? 1 : -1];
void metadata_to_buf(char** buf, const FileMetadata* m) {
int32_t present = (m != NULL) ? 1 : 0;
memcpy(*buf, &present, sizeof(present));
-17
View File
@@ -6,23 +6,6 @@
#include <stdint.h>
#include <sys/stat.h>
/*
* Wire format (introduced in protocol version 2.0.0):
* int32_t present
* int32_t mode (was mode_t, platform-dependent)
* int32_t uid (was uid_t, platform-dependent)
* int32_t gid (was gid_t, platform-dependent)
* int64_t mtime_sec (was time_t, platform-dependent)
* int64_t mtime_nsec (was long, platform-dependent)
*
* Prior to 2.0.0 the wire format used the raw platform-dependent types,
* which broke compatiblity across different systems. All fields are now
* serialized as fixed-width integers.
*/
/* Size of metadata fields on wire, excluding the int32_t `present` field that
* is always sent first. The total wire size for present metadata is
* sizeof(int32_t) + FILE_METADATA_WIRE_SIZE (32 bytes on most platforms). */
#define FILE_METADATA_WIRE_SIZE (sizeof(int32_t) * 3 + sizeof(int64_t) * 2)
void metadata_to_buf(char** buf, const FileMetadata* m);
+15 -10
View File
@@ -34,11 +34,14 @@ static void bw_throttle(size_t bytes_written) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
long long elapsed_ns =
(now.tv_sec - bw_last_refill.tv_sec) * 1000000000LL + (now.tv_nsec - bw_last_refill.tv_nsec);
/* Use unsigned long long for elapsed_ns to avoid overflow in multiplication.
* time_t differences fit comfortably in 64-bit for any practical runtime. */
unsigned long long elapsed_ns =
(unsigned long long)(now.tv_sec - bw_last_refill.tv_sec) * 1000000000ULL +
(unsigned long long)(now.tv_nsec - bw_last_refill.tv_nsec);
bw_last_refill = now;
long long tokens_to_add = (long long)((double)io_bwlimit * elapsed_ns / 1000000000.0);
long long tokens_to_add = (long long)((double)io_bwlimit * (double)elapsed_ns / 1000000000.0);
bw_tokens += tokens_to_add;
if (bw_tokens > (long long)io_bwlimit)
bw_tokens = (long long)io_bwlimit;
@@ -46,7 +49,9 @@ static void bw_throttle(size_t bytes_written) {
bw_tokens -= (long long)bytes_written;
if (bw_tokens < 0) {
long long deficit_ns = (long long)((double)(-bw_tokens) / io_bwlimit * 1000000000.0);
long long deficit_ns = (long long)((double)(-bw_tokens) / (double)io_bwlimit * 1000000000.0);
if (deficit_ns < 0)
deficit_ns = 0;
struct timespec sleep_time, remaining;
sleep_time.tv_sec = deficit_ns / 1000000000LL;
sleep_time.tv_nsec = deficit_ns % 1000000000LL;
@@ -107,7 +112,7 @@ bool receive_n_data(int file_descriptor, void* data, size_t data_size) {
bytes_received =
read(fd, (char*)data + total_bytes_received, data_size - total_bytes_received);
if (bytes_received <= 0) {
if (io_ssl && bytes_received < 0) {
if (io_ssl) {
int ssl_err = SSL_get_error(io_ssl, (int)bytes_received);
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE)
continue;
@@ -188,18 +193,18 @@ bool send_data(int file_descriptor, const Data* data) {
return false;
if (!send_n_data(file_descriptor, data->data, data_size))
return false;
log_message(LOG_LEVEL_DEBUG, "Send %llu data", data_size);
log_message(LOG_LEVEL_DEBUG, "Send %lld data", data_size);
return true;
}
#define MAX_DATA_SIZE (1024ULL * 1024 * 1024)
#define MAX_DATA_SIZE (1024ULL * 1024 * 1024) // 1 GB
Data* receive_data(int file_descriptor) {
unsigned long long size = 0;
if (!receive_n_data(file_descriptor, &size, sizeof(unsigned long long)))
return NULL;
if ((size_t)size != size || size > MAX_DATA_SIZE) {
log_message(LOG_LEVEL_ERROR, "receive_data size %llu exceeds limits", size);
if (size > MAX_DATA_SIZE) {
log_message(LOG_LEVEL_ERROR, "receive_data: size %llu exceeds maximum", size);
return NULL;
}
void* data = malloc((size_t)size);
@@ -209,7 +214,7 @@ Data* receive_data(int file_descriptor) {
free(data);
return NULL;
}
log_message(LOG_LEVEL_DEBUG, "Received %llu data", size);
log_message(LOG_LEVEL_DEBUG, "Received %lld data", size);
return data_create(data, (size_t)size);
}
+5 -9
View File
@@ -67,7 +67,7 @@ static int parse_remote_dest(const char* dest, RemoteDest* r) {
return 0;
}
Client* client_connect_ssh(const char* destination, int port, const char* server_path) {
Client* client_connect_ssh(const char* destination, int port) {
RemoteDest r;
if (parse_remote_dest(destination, &r) != 0) {
fprintf(stderr, "Invalid remote destination: %s\n", destination);
@@ -119,13 +119,10 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
close(sv[1]);
char ssh_user[512];
int needed;
if (r.user && r.user[0] != '\0')
needed = snprintf(ssh_user, sizeof(ssh_user), "%s@%s", r.user, r.host);
snprintf(ssh_user, sizeof(ssh_user), "%s@%s", r.user, r.host);
else
needed = snprintf(ssh_user, sizeof(ssh_user), "%s", r.host);
if ((size_t)needed >= sizeof(ssh_user))
fprintf(stderr, "Warning: ssh_user string truncated\n");
snprintf(ssh_user, sizeof(ssh_user), "%s", r.host);
size_t ssh_argv_max = 32;
char** ssh_argv = calloc(ssh_argv_max, sizeof(char*));
@@ -152,7 +149,7 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
_exit(1);
}
ssh_argv[ac++] = ssh_user;
ssh_argv[ac++] = (char*)(server_path ? server_path : "fastsync-server");
ssh_argv[ac++] = "fastsync-server";
ssh_argv[ac++] = "--stdio";
ssh_argv[ac] = NULL;
execvp("ssh", ssh_argv);
@@ -174,8 +171,7 @@ Client* client_connect_ssh(const char* destination, int port, const char* server
close(sv[0]);
waitpid(pid, NULL, 0);
remote_dest_destroy(&r);
fprintf(stderr, "Error: could not launch '%s --stdio' on remote\n",
server_path ? server_path : "fastsync-server");
fprintf(stderr, "Error: could not launch 'fastsync-server --stdio' on remote\n");
return NULL;
}
+1 -1
View File
@@ -3,6 +3,6 @@
#include "transport_tcp.h"
Client* client_connect_ssh(const char* destination, int port, const char* server_path);
Client* client_connect_ssh(const char* destination, int port);
#endif
+8 -13
View File
@@ -42,13 +42,14 @@ Server* server_create(int port) {
return NULL;
}
memset(&server->address, 0, sizeof(server->address));
server->ssl_ctx = NULL;
// Try IPv6 first, fall back to IPv4
int fd = socket(AF_INET6, SOCK_STREAM, 0);
sa_family_t domain = AF_INET6;
int domain = AF_INET6;
int fd = socket(domain, SOCK_STREAM, 0);
if (fd < 0) {
fd = socket(AF_INET, SOCK_STREAM, 0);
domain = AF_INET;
fd = socket(domain, SOCK_STREAM, 0);
}
if (fd < 0) {
perror("Could not create Socket!");
@@ -63,7 +64,6 @@ Server* server_create(int port) {
}
server->file_descriptor = fd;
server->ssl_ctx = NULL;
int opt = 1;
if (setsockopt(server->file_descriptor, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
perror("Error setting a socket option!");
@@ -72,7 +72,6 @@ Server* server_create(int port) {
return NULL;
}
// Use the domain from the socket we actually created
struct sockaddr_storage* addr = &server->address;
struct sockaddr_in* addr4 = (struct sockaddr_in*)addr;
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)addr;
@@ -81,13 +80,11 @@ Server* server_create(int port) {
addr6->sin6_family = AF_INET6;
addr6->sin6_addr = in6addr_any;
addr6->sin6_port = htons(port);
addr->ss_family = AF_INET6;
server->address_length = sizeof(struct sockaddr_in6);
} else {
addr4->sin_family = AF_INET;
addr4->sin_addr.s_addr = INADDR_ANY;
addr4->sin_port = htons(port);
addr->ss_family = AF_INET;
server->address_length = sizeof(struct sockaddr_in);
}
@@ -268,11 +265,10 @@ bool client_connect(Client* client, char* host, int port) {
}
// Save the connected address
socklen_t addr_len = rp->ai_addrlen;
if (addr_len > sizeof(client->address))
addr_len = sizeof(client->address);
memcpy(&client->address, rp->ai_addr, addr_len);
client->address_length = addr_len;
size_t copy_len =
rp->ai_addrlen < sizeof(client->address) ? rp->ai_addrlen : sizeof(client->address);
memcpy(&client->address, rp->ai_addr, copy_len);
client->address_length = (int)copy_len;
freeaddrinfo(res);
// Close old fd if any and set new one
@@ -303,7 +299,6 @@ void client_disconnect(Client* client) {
void client_delete(Client* client) {
if (client == NULL)
return;
client_disconnect(client);
if (client->ssl_ctx) {
SSL_CTX_free(client->ssl_ctx);
client->ssl_ctx = NULL;
+5 -4
View File
@@ -134,7 +134,7 @@ static void delete_extras_walk(const char* abs_path, const char* rel_path, Array
if (!dir)
return;
bool all_removed = true;
const struct dirent* entry;
struct dirent* entry;
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
@@ -184,17 +184,18 @@ void delete_extras(const char* dest_root, ArrayList* manifest) {
delete_extras_walk(dest_root, "", manifest);
}
char* path_cat(const char* path1, const char* path2) {
char* path_cat(const char* path1, char* path2) {
if (path1 == NULL || *path1 == '\0')
return str_dup(path2);
if (path2 == NULL || *path2 == '\0')
return str_dup(path1);
int path1_len = strlen(path1);
int path2_len = strlen(path2);
char* path2_pointer = path2;
if (path1[path1_len - 1] == '/')
path1_len -= 1;
if (path2[0] == '/') {
path2++;
path2_pointer += 1;
path2_len -= 1;
}
char* new_path = malloc(path1_len + path2_len + 2);
@@ -202,7 +203,7 @@ char* path_cat(const char* path1, const char* path2) {
return NULL;
memcpy(new_path, path1, path1_len);
new_path[path1_len] = '/';
memcpy(new_path + path1_len + 1, path2, path2_len);
memcpy(new_path + path1_len + 1, path2_pointer, path2_len);
new_path[path1_len + path2_len + 1] = '\0';
return new_path;
}
+1 -1
View File
@@ -6,7 +6,7 @@
bool mkdir_r(const char* path);
char* str_dup(const char* string);
char* path_cat(const char* path1, const char* path2);
char* path_cat(const char* path1, char* path2);
bool glob_match(const char* pattern, const char* str);
void delete_extras(const char* dest_root, ArrayList* manifest);
+1 -1
View File
@@ -224,7 +224,7 @@ static void test_sendfile_no_path() {
pid_t pid = fork();
if (pid == 0) {
close(p[1]);
/* When send_path is false, the sender still sends file_type + data */
/* Read file type indicator */
int file_type;
EXPECT_TRUE(receive_int(p[0], &file_type));
EXPECT_EQ_INT(file_type, (int)FILE_TYPE_REGULAR);
+2 -5
View File
@@ -46,7 +46,6 @@ static void test_send_receive_str() {
EXPECT_TRUE(send_str(0, ""));
/* cppcheck-suppress constVariablePointer */
char* received = receive_str(0);
EXPECT_NOT_NULL(received);
EXPECT_EQ_STR(received, "");
@@ -64,7 +63,6 @@ static void test_send_receive_str_normal() {
EXPECT_TRUE(send_str(0, "Hello, Protocol!"));
/* cppcheck-suppress constVariablePointer */
char* received = receive_str(0);
EXPECT_NOT_NULL(received);
EXPECT_EQ_STR(received, "Hello, Protocol!");
@@ -80,7 +78,6 @@ static void test_send_receive_data() {
io_set_fds(p[0], p[1]);
io_set_bwlimit(0);
/* cppcheck-suppress constVariablePointer */
unsigned char bin[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0xFF};
void* buf = malloc(sizeof(bin));
EXPECT_NOT_NULL(buf);
@@ -131,7 +128,6 @@ static void test_send_receive_status() {
io_set_fds(p[0], p[1]);
io_set_bwlimit(0);
/* cppcheck-suppress constVariablePointer */
Status statuses[] = {STATUS_OK, STATUS_ERROR, STATUS_FINISHED, STATUS_NEXT,
STATUS_CHUNK, STATUS_CHECK, STATUS_DELTA_SIGNATURE, STATUS_DELTA_DATA};
int count = sizeof(statuses) / sizeof(statuses[0]);
@@ -183,7 +179,8 @@ static void test_receive_str_oversized() {
size_t huge = MAX_STRING_SIZE + 1;
EXPECT_TRUE(send_n_data(0, &huge, sizeof(size_t)));
const char* received = receive_str(0);
/* cppcheck-suppress constVariablePointer */
char* received = receive_str(0);
EXPECT_NULL(received);
close(p[0]);
+27 -14
View File
@@ -15,7 +15,7 @@ static void test_scanner_single_file() {
const char* file1 = "test_scan_dir_single/file1.txt";
const char* content1 = "hello scanner";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(file1, content1);
DirectoryScanner* scanner =
@@ -43,7 +43,7 @@ static void test_scanner_multiple_files() {
const char* content1 = "alpha";
const char* content2 = "beta";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(file1, content1);
create_test_file(file2, content2);
@@ -82,8 +82,8 @@ static void test_scanner_subdirectory() {
const char* sub_file = "test_scan_sub/sub/sub_file.txt";
const char* content = "nested content";
EXPECT_EQ_INT(mkdir(root, 0755), 0);
EXPECT_EQ_INT(mkdir(sub, 0755), 0);
mkdir(root, 0755);
mkdir(sub, 0755);
create_test_file(root_file, content);
create_test_file(sub_file, content);
@@ -109,7 +109,7 @@ static void test_scanner_subdirectory() {
static void test_scanner_empty_directory() {
const char* dir = "test_scan_empty";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
DirectoryScanner* scanner =
directory_scanner_create((char*)dir, false, 0, NULL, 0, NULL, 0, 0, 0);
@@ -130,7 +130,7 @@ static void test_scanner_exclude_pattern() {
const char* f_tmp = "test_scan_excl/remove.tmp";
const char* content = "data";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(f_txt, content);
create_test_file(f_tmp, content);
@@ -154,6 +154,8 @@ static void test_scanner_exclude_pattern() {
}
static void test_scanner_exclude_subdirectory() {
/* Exclude patterns match filenames only (via entry->d_name).
* Files inside subdirectories are also matched by filename. */
const char* root = "test_scan_excl_sub";
const char* sub = "test_scan_excl_sub/sub";
const char* root_txt = "test_scan_excl_sub/root.txt";
@@ -161,12 +163,13 @@ static void test_scanner_exclude_subdirectory() {
const char* sub_tmp = "test_scan_excl_sub/sub/temp.tmp";
const char* content = "data";
EXPECT_EQ_INT(mkdir(root, 0755), 0);
EXPECT_EQ_INT(mkdir(sub, 0755), 0);
mkdir(root, 0755);
mkdir(sub, 0755);
create_test_file(root_txt, content);
create_test_file(sub_txt, content);
create_test_file(sub_tmp, content);
/* Exclude *.tmp — should exclude sub/temp.tmp but keep root.txt and sub/data.txt */
char* exclude[] = {"*.tmp"};
DirectoryScanner* scanner =
directory_scanner_create((char*)root, false, 0, exclude, 1, NULL, 0, 0, 0);
@@ -177,6 +180,7 @@ static void test_scanner_exclude_subdirectory() {
while ((chunk = directory_scanner_next(scanner)) != NULL) {
total += chunk->element_count;
for (int i = 0; i < chunk->element_count; i++) {
/* No path should end in .tmp */
size_t len = strlen(chunk->items[i]->path);
EXPECT_TRUE(len < 4 || strcmp(chunk->items[i]->path + len - 4, ".tmp") != 0);
}
@@ -193,17 +197,22 @@ static void test_scanner_exclude_subdirectory() {
}
static void test_scanner_include_and_exclude() {
/* In the scanner, exclude is checked first and takes precedence.
* Include patterns act as an additional filter: if include_count > 0,
* the file must match one of the include patterns (after not being excluded).
* This test uses non-overlapping exclude and include patterns. */
const char* dir = "test_scan_inc_exc";
const char* f_txt = "test_scan_inc_exc/a.txt";
const char* f_log = "test_scan_inc_exc/b.log";
const char* f_bak = "test_scan_inc_exc/c.bak";
const char* content = "filter";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(f_txt, content);
create_test_file(f_log, content);
create_test_file(f_bak, content);
/* Exclude *.bak. Include *.txt and *.log. */
char* exclude[] = {"*.bak"};
char* include[] = {"*.txt", "*.log"};
DirectoryScanner* scanner =
@@ -221,6 +230,7 @@ static void test_scanner_include_and_exclude() {
if (strstr(chunk->items[i]->path, "b.log"))
found_log = 1;
}
/* a.txt included by *.txt, b.log included by *.log, c.bak excluded by *.bak */
EXPECT_TRUE(found_txt);
EXPECT_TRUE(found_log);
@@ -238,7 +248,10 @@ static void test_scanner_max_size() {
const char* dir = "test_scan_max";
const char* small = "test_scan_max/small.txt";
const char* large = "test_scan_max/large.txt";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
create_test_file(small, "tiny");
create_test_file(large, "this_content_is_longer_than_ten_chars");
mkdir(dir, 0755);
create_test_file(small, "tiny");
create_test_file(large, "this_content_is_longer_than_ten_chars");
@@ -266,7 +279,7 @@ static void test_scanner_min_size() {
const char* empty_f = "test_scan_min/empty.txt";
const char* data_f = "test_scan_min/data.txt";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(empty_f, "");
create_test_file(data_f, "some content here");
@@ -295,7 +308,7 @@ static void test_scanner_size_range() {
const char* medium = "test_scan_range/med.txt";
const char* huge = "test_scan_range/huge.txt";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(tiny, "ab");
create_test_file(medium, "hello world");
create_test_file(huge, "this is a much larger file for testing size filters");
@@ -328,7 +341,7 @@ static void test_scanner_mixed_patterns() {
const char* c_txt = "test_scan_mixed/c.txt"; /* size ~= 5 */
const char* d_bak = "test_scan_mixed/d.bak"; /* size ~= 42 */
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(a_txt, "aaaaa");
create_test_file(b_bin, "bbbbbbbbbbbbb");
create_test_file(c_txt, "ccccc");
@@ -364,7 +377,7 @@ static void test_scanner_no_patterns() {
const char* f1 = "test_scan_none/f1.txt";
const char* f2 = "test_scan_none/f2.txt";
EXPECT_EQ_INT(mkdir(dir, 0755), 0);
mkdir(dir, 0755);
create_test_file(f1, "first");
create_test_file(f2, "second");
+4 -4
View File
@@ -9,14 +9,14 @@
static void test_ssh_connect_invalid_dest() {
/* Missing colon — parse_remote_dest should fail and return NULL */
/* cppcheck-suppress constVariablePointer */
Client* client = client_connect_ssh("invalid-destination-no-colon", 22, NULL);
Client* client = client_connect_ssh("invalid-destination-no-colon", 22);
EXPECT_NULL(client);
}
/* Test client_connect_ssh with empty destination */
static void test_ssh_connect_empty_dest() {
/* cppcheck-suppress constVariablePointer */
Client* client = client_connect_ssh("", 22, NULL);
Client* client = client_connect_ssh("", 22);
EXPECT_NULL(client);
}
@@ -24,7 +24,7 @@ static void test_ssh_connect_empty_dest() {
* parse_remote_dest succeeds, ssh is exec'd and fails, but the function
* creates a Client that must be cleaned up. */
static void test_ssh_connect_malformed() {
Client* client = client_connect_ssh(":", 22, NULL);
Client* client = client_connect_ssh(":", 22);
/* ssh binary exists, so exec succeeds; the function returns a Client.
* We just verify it doesn't crash and clean up properly. */
if (client != NULL) {
@@ -37,7 +37,7 @@ static void test_ssh_connect_malformed() {
/* Test client_connect_ssh with valid format but unreachable host.
* The function launches ssh which will fail to connect, returns a Client. */
static void test_ssh_connect_unreachable() {
Client* client = client_connect_ssh("nonexistent.invalid:/remote/path", 22, NULL);
Client* client = client_connect_ssh("nonexistent.invalid:/remote/path", 22);
if (client != NULL) {
client_disconnect(client);
client_delete(client);
+1 -1
View File
@@ -9,7 +9,7 @@ static void test_client_create_delete() {
Client* client = client_create();
EXPECT_NOT_NULL(client);
EXPECT_EQ_INT(client->file_descriptor, -1);
EXPECT_EQ_INT(client->address.ss_family, AF_UNSPEC);
EXPECT_TRUE(client->address.ss_family == AF_UNSPEC);
EXPECT_EQ_INT(client->ssh_child_pid, -1);
EXPECT_NULL(client->ssl);
EXPECT_NULL(client->ssl_ctx);