From 6d050926eea6ce2124bc4207116c48e9f624a886 Mon Sep 17 00:00:00 2001 From: Jonathan Senkerik Date: Tue, 17 Feb 2026 23:06:35 -0500 Subject: [PATCH] fixes for MR --- main.cpp | 21 +++++++++++++++++++-- pclsync/pdiff.c | 3 ++- pclsync/pfs.c | 17 +++++++++++------ pclsync/pssl.c | 6 +++--- pclsync_lib.cpp | 8 ++++++-- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index a9aff5d..eb74227 100644 --- a/main.cpp +++ b/main.cpp @@ -145,6 +145,11 @@ int main(int argc, char **argv) { if (vm.count("cache-size")) { uint64_t cache_size_gb = vm["cache-size"].as(); + /* Validate cache size: minimum 1GB, maximum 1TB */ + if (cache_size_gb < 1 || cache_size_gb > 1024) { + std::cerr << "error: cache-size must be between 1 and 1024 GB" << std::endl; + return 1; + } uint64_t cache_size_bytes = cache_size_gb * 1024ULL * 1024ULL * 1024ULL; char cache_size_str[32]; snprintf(cache_size_str, sizeof(cache_size_str), "%llu", @@ -153,7 +158,13 @@ int main(int argc, char **argv) { } if (vm.count("log-path")) { - setenv("PCLOUD_LOG_PATH", vm["log-path"].as().c_str(), 1); + std::string log_path = vm["log-path"].as(); + /* Validate log path: must not be empty or start with /etc or /sys */ + if (log_path.empty() || log_path.compare(0, 5, "/etc/") == 0 || log_path.compare(0, 5, "/sys/") == 0) { + std::cerr << "error: invalid log-path" << std::endl; + return 1; + } + setenv("PCLOUD_LOG_PATH", log_path.c_str(), 1); } if (vm.count("log-level")) { @@ -164,7 +175,13 @@ int main(int argc, char **argv) { } if (vm.count("fs-event-log")) { - setenv("PCLOUD_FS_EVENT_LOG", vm["fs-event-log"].as().c_str(), 1); + std::string fs_event_log = vm["fs-event-log"].as(); + /* Validate fs-event-log path: must not be empty or start with /etc or /sys */ + if (fs_event_log.empty() || fs_event_log.compare(0, 5, "/etc/") == 0 || fs_event_log.compare(0, 5, "/sys/") == 0) { + std::cerr << "error: invalid fs-event-log" << std::endl; + return 1; + } + setenv("PCLOUD_FS_EVENT_LOG", fs_event_log.c_str(), 1); } if (vm.count("fuse-opts")) { diff --git a/pclsync/pdiff.c b/pclsync/pdiff.c index 4c12e69..f888af4 100644 --- a/pclsync/pdiff.c +++ b/pclsync/pdiff.c @@ -1629,6 +1629,8 @@ static void process_modifyfile(const binresult *entry) { path = pfolder_file_path(fileid, NULL); ptask_lfile_rm(fileid, path); free(path); + free(oldfilepath); + free(oldfilepath_rel); needdownload = 1; return; } @@ -1728,7 +1730,6 @@ static void process_deletefile(const binresult *entry) { pdownload_tasks_delete(fileid, 0, 1); path = pfolder_file_path(fileid, NULL); if (likely(path)) { - pdbg_logf(D_NOTICE, "remote file deleted %s", path); ptask_lfile_rm(fileid, path); free(path); needdownload = 1; diff --git a/pclsync/pfs.c b/pclsync/pfs.c index 180eaac..dca1a76 100644 --- a/pclsync/pfs.c +++ b/pclsync/pfs.c @@ -3695,7 +3695,8 @@ static int psync_fs_do_start() { if (fuse_opts_env && fuse_opts_env[0] != '\0') { char *fuse_opts = strdup(fuse_opts_env); if (fuse_opts) { - char *token = strtok(fuse_opts, ","); + char *saveptr = NULL; + char *token = strtok_r(fuse_opts, ",", &saveptr); while (token) { // Trim leading/trailing whitespace while (*token == ' ' || *token == '\t') token++; @@ -3703,12 +3704,16 @@ static int psync_fs_do_start() { while (end > token && (*end == ' ' || *end == '\t')) *end-- = '\0'; if (strlen(token) > 0) { - char opt_arg[256]; - snprintf(opt_arg, sizeof(opt_arg), "-o%s", token); - fuse_opt_add_arg(&args, opt_arg); - pdbg_logf(D_NOTICE, "Adding FUSE option: %s", token); + if (strlen(token) > 250) { + pdbg_logf(D_WARNING, "FUSE option too long, skipping: %s", token); + } else { + char opt_arg[256]; + snprintf(opt_arg, sizeof(opt_arg), "-o%s", token); + fuse_opt_add_arg(&args, opt_arg); + pdbg_logf(D_NOTICE, "Adding FUSE option: %s", token); + } } - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &saveptr); } free(fuse_opts); } diff --git a/pclsync/pssl.c b/pclsync/pssl.c index 6a48c42..1398724 100644 --- a/pclsync/pssl.c +++ b/pclsync/pssl.c @@ -801,9 +801,9 @@ prsa_sign_sha256_hash(psync_rsa_privatekey_t rsa, if (!ret) return (psync_rsa_signature_t)(void *)PERROR_NO_MEMORY; ret->datalen = rsalen; - /* Save current padding settings (assume PKCS_V21 with SHA1 as default) */ - padding = MBEDTLS_RSA_PKCS_V21; - hash_id = MBEDTLS_MD_SHA1; + /* Save current padding settings using getter functions */ + padding = mbedtls_rsa_get_padding_mode(rsa); + hash_id = mbedtls_rsa_get_md_alg(rsa); mbedtls_rsa_set_padding(rsa, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA256); if (mbedtls_rsa_rsassa_pss_sign(rsa, rng_get, &rng, MBEDTLS_MD_SHA256, diff --git a/pclsync_lib.cpp b/pclsync_lib.cpp index 7e048a6..0dce89f 100644 --- a/pclsync_lib.cpp +++ b/pclsync_lib.cpp @@ -504,8 +504,12 @@ int clib::pclsync_lib::init() { const char *cache_size_env = getenv("PCLOUD_CACHE_SIZE"); if (cache_size_env && cache_size_env[0] != '\0') { - uint64_t cache_size = std::stoull(cache_size_env); - psync_set_uint_setting("fscachesize", cache_size); + try { + uint64_t cache_size = std::stoull(cache_size_env); + psync_set_uint_setting("fscachesize", cache_size); + } catch (const std::exception &e) { + pdbg_logf(D_ERROR, "Invalid PCLOUD_CACHE_SIZE: %s", cache_size_env); + } } psync_start_sync(status_change, event_handler);