Commit Graph

280 Commits

Author SHA1 Message Date
Levi Neely deb61a40f8 Fix pmem.c infinite recursion - use raw malloc/free internally 2026-03-08 19:30:22 +01:00
Levi Neely 86460c7568 Fix ptask.c callback arguments - remove PMEM_SUBSYS_OTHER from s->free calls 2026-03-08 19:22:20 +01:00
Levi Neely b839a9a6a9 Fix ptask.c compilation errors - replace s->pmem_free with s->free 2026-03-08 19:20:08 +01:00
Levi Neely 6efaac5370 Add pmem.h include to 10 files missing it 2026-03-08 19:17:52 +01:00
Levi Neely 709e6d7fe9 Add pmem.h include to pdbg.c 2026-03-08 19:15:48 +01:00
Levi Neely 4fb8078978 Fix pcache.c compilation errors - replace he->pmem_free with pmem_free 2026-03-08 19:13:42 +01:00
Levi Neely bc36713350 Migrate papi.c, ptools.c, pbusinessaccount.c to PMEM_SUBSYS_API 2026-03-08 19:11:04 +01:00
Levi Neely 7d10cf8d6c Migrate remaining 34 files to pmem_malloc/pmem_free 2026-03-08 19:08:22 +01:00
Levi Neely 70dbe0104c Fix panic() infinite recursion by unregistering handlers before abort() 2026-03-08 18:57:16 +01:00
Levi Neely a53b09362f Register panic handlers early in main() 2026-03-08 18:38:14 +01:00
Levi Neely bf1d1caf2f Add panic() with backtrace to psignal module 2026-03-08 18:25:57 +01:00
Levi Neely b0f071ef23 Fix multiplication pattern in psock.c with overflow checks 2026-03-08 18:06:47 +01:00
Levi Neely 9f8f25183e Migrate psock.c malloc/free to pmem_malloc/pmem_free 2026-03-08 18:03:03 +01:00
Levi Neely 3f17f6333d Migrate pupload.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:53:56 +01:00
Levi Neely 9113a17ca8 Migrate pcrypto.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:52:03 +01:00
Levi Neely 66faf0e7cd Migrate pdiff.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:45:10 +01:00
Levi Neely 95d02868af Migrate pfsupload.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:40:25 +01:00
Levi Neely 655e14a485 Fix multiplication patterns in putil.c encoding functions with overflow checks 2026-03-08 17:30:52 +01:00
Levi Neely b74f5f2049 Migrate putil.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:26:36 +01:00
Levi Neely 827722724a Migrate psql.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:21:37 +01:00
Levi Neely 7cebfd6e58 Migrate plocalscan.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:16:58 +01:00
Levi Neely 3b5e34cfd6 Migrate publiclinks.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:12:25 +01:00
Levi Neely 37497aace2 Fix multiplication patterns in pfolder.c with overflow checks 2026-03-08 17:08:22 +01:00
Levi Neely f2c1ee615f Migrate pfolder.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:04:39 +01:00
Levi Neely 115cbba660 Migrate pcryptofolder.c malloc/free to pmem_malloc/pmem_free 2026-03-08 17:00:52 +01:00
Levi Neely 0ca4b25821 Migrate pssl.c malloc/free to pmem_malloc/pmem_free 2026-03-08 16:38:41 +01:00
Levi Neely f578c80a50 Fix remaining multiplication pattern in ppagecache.c line 3239 2026-03-08 16:33:48 +01:00
Levi Neely e495309ae3 Migrate ppagecache.c malloc/free to pmem_malloc/pmem_free 2026-03-08 16:30:54 +01:00
Levi Neely 0fcee5cd75 Fix multiplication patterns in pnetlibs.c with pmem_malloc_array 2026-03-08 16:25:42 +01:00
Levi Neely 84c8d2a0ee Migrate pnetlibs.c malloc/free to pmem_malloc/pmem_free 2026-03-08 16:22:44 +01:00
Levi Neely fd19b075ae Migrate pfstasks.c malloc/free to pmem_malloc/pmem_free 2026-03-08 16:17:12 +01:00
Levi Neely 3f7f9d716c Add overflow-safe pmem_malloc_array function 2026-03-08 16:04:20 +01:00
Levi Neely 964a5fcde9 Migrate malloc/calloc to pmem_malloc with subsystem tracking 2026-03-08 15:55:33 +01:00
Levi Neely fc44baab8b Implement memory accounting infrastructure 2026-03-08 15:45:26 +01:00
Levi Neely 8276034f70
Add lock ordering assertions in debug builds (#370)
* Add lock ordering assertions for psql_lock → file mutex

* Add missing psql.h include to pfs.h

* Fix debug build conditional compilation for lock ordering assertions

* Fix function declaration order for pfs_debug_check_lock_order

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 15:38:41 +01:00
Levi Neely d0c213f181
Add overflow-safe allocation wrapper pmem_calloc_safe() (#369)
* Add overflow-safe allocation wrappers to pmem module

* Replace malloc(nmemb*size) with pmem_calloc_safe in high-risk sites

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 14:55:21 +01:00
Levi Neely 89ef8663b0
Add psignal module for centralized signal handling (#368)
* Add psignal module for centralized signal handling

- Added pclsync/psignal.h with psignal_register() and psignal_check_pending() API
- Added pclsync/psignal.c with async-signal-safe handlers for SIGINT, SIGTERM, SIGHUP
- Implements flag-based deferred signal handling pattern

* Integrate psignal into main loop and remove conflicting handlers

- Added extern "C" linkage to psignal.h for C++ compatibility
- Integrated psignal_check_pending() into pclsync_lib.cpp main loop
- Integrated psignal_check_pending() into ptimer.c timer loop
- Removed conflicting signal handlers from pfs.c

* Migrate psync_set_signal to psignal module

- Added psignal_set_custom_handler() to psignal.h and psignal.c
- Replaced psync_set_signal() calls in pfs.c with psignal_set_custom_handler()
- Centralizes all signal handling in psignal module

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 14:27:21 +01:00
Levi Neely 9d4143f1f0
Add clang-tidy signal safety checks (pcl-2s2.2) (#367)
Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 13:41:51 +01:00
Levi Neely 5ad532b692
Add NULL check audit to high-risk allocations (#366)
Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 13:11:41 +01:00
Levi Neely f9e362fd24
Add signal safety test suite (#365)
* Add signal safety test suite

* Remove binary file from repository

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 12:07:30 +01:00
Levi Neely 645596ac15
Add deadlock detection with timeouts (#364)
Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-08 11:55:25 +01:00
Levi Neely 5769bb4882
Fix pcl-10w: remove IS_DEBUG conditional from psql.h (#363)
Removed IS_DEBUG conditional block from psql.h. Added psql_dump_locks() declaration. Now uses single API without debug/release variants. This eliminates the last remaining use of IS_DEBUG after PR #177.

Fixes #178

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-07 21:37:21 +01:00
Levi Neely 6a0edf0cc3
Fix pcl-ivv: remove weak attribute from debug hooks (#362)
Removed weak attribute from debug hooks (psys_debug_abort_on_sqllock and psys_debug_configure_core_dump). Made functions static in psys.c and removed declarations from psys.h. Functions can no longer be overridden by external libraries, preventing potential code execution and security bypass.

Fixes #289

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-07 20:18:51 +01:00
Levi Neely 431f94725f
Fix pcl-r0j: rename psync_delete_sync_by_folderid to pfolder_delete_sync_by_id (#361)
Renamed psync_delete_sync_by_folderid to pfolder_delete_sync_by_id to align with pfolder API naming conventions. Updated all callers.

Fixes #100

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-07 19:54:21 +01:00
Levi Neely 1bf831c00f
Fix pcl-ue8: operator precedence in GetState() (#360)
Separated assignment from condition so rep contains Call() return value.
Removed incorrect wrapper that prevented state checks from executing.
Now rep values 10/11/12 properly set state.

Fixes #180

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-07 19:40:07 +01:00
Levi Neely f17fb19b85
Fix log file permissions: use mode 0600 (#359)
Replace fopen() with open()+fdopen() for all log file creation
in pdbg.c to ensure files are created with mode 0600, preventing
world-readable logs that may contain sensitive information.

Fixes #290

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-07 19:20:51 +01:00
Levi Neely e37c7f5894
Fix pcl-dls: errPtr memory leak between ptools_backend_call() calls in ptools_set_backend_file_dates() (#358)
* Fix pcl-dls.1: free errPtr between calls in ptools_set_backend_file_dates()

char *errPtr was already used instead of char msgErr[1024], but was
not freed between the two ptools_backend_call() invocations. If the
first call allocated errPtr, the second would overwrite the pointer
without freeing it. Add free(errPtr); errPtr = NULL; between the two
calls to eliminate the leak.

Ref GH #194.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add ptools_set_backend_file_dates() errPtr lifecycle tests (pcl-dls)

6 test cases using malloc/free wrapping covering both-succeed,
call1-error, call2-error, both-errors, pre-fix leak demonstration,
and no-double-free after mid-free NULLing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 19:01:17 +01:00
Levi Neely 0430d0b872
Fix pcl-aex: validate PCLOUD_LOG_PATH to prevent arbitrary file write and log injection (#357)
* Fix pcl-aex.1: validate PCLOUD_LOG_PATH before use in psync_debug_path()

Add pdbg_path_is_safe() helper that rejects PCLOUD_LOG_PATH values
that are not absolute, contain '..' path components, or do not resolve
under the user HOME directory or /tmp. On rejection, fall back to the
default ~/.pcloud/debug.log path and emit a warning to stderr.

Also fix a pre-existing memory leak: ppath_home() return was not freed
in the default-path branch.

Ref GH #291.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add PCLOUD_LOG_PATH path-safety tests (pcl-aex)

28 test cases covering relative paths, '..' traversal, paths outside
HOME and /tmp, valid accepted paths, and psync_debug_path() env
fallback behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:53:17 +01:00
Levi Neely 045aad673a
Fix pcl-aqb: pthread_create unchecked return, thread_data leak, and function-pointer cast UB in prun.c (#356)
* Fix pcl-aqb.1: eliminate function-pointer cast UB in start_thread() via union

Replace the single void* run field in thread_data with a union
{ thread0_run run0; thread1_run run1 } so each function pointer is
stored and retrieved at its correct type, eliminating the
thread0_run <-> thread1_run cast chain UB. Split start_thread() into
prun_thread() and prun_thread1() that each populate the appropriate
union member, backed by a shared start_thread_common() helper. Add
malloc NULL check with error log in both public functions.
pthread_create failure handling (log + free) was already present.

Ref GH #199.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add prun start_thread() resource-leak and UB tests (pcl-aqb)

8 test cases using linker interposition covering pthread_create
failure data-free, attr_destroy on failure, malloc failure graceful
return, union fn storage without cast, and success path accounting.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:44:47 +01:00
Levi Neely 60e43edec4
Fix pcl-a1j: buffer overflow in ptools_create_backend_event() via unchecked sprintf and strcat (#355)
* Fix pcl-a1j.1: replace sprintf with snprintf and add strcat length check in ptools_create_backend_event()

Add paramname length check (> 254 bytes → skip with warning) before
snprintf into charBuff[i][258], and validate the snprintf return
value. Add explicit length check before strcat into keyParams to
prevent overflow when paramname exceeds remaining buffer space.
Eliminates buffer overflow from long paramname.

Ref GH #195.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix pcl-a1j.1: clamp pCnt to PTOOLS_MAX_PARAMS to prevent charBuff stack overflow

charBuff[30][258] is a fixed-size stack array but pCnt was unbounded,
allowing any caller with params->paramCnt > 30 to overflow the stack
via charBuff[i] access. Add PTOOLS_MAX_PARAMS (30) define, use it to
size charBuff, and clamp pCnt to PTOOLS_MAX_PARAMS with a warning log
before the loop.

Ref GH #195.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add ptools_create_backend_event() validation tests (pcl-a1j)

11 test cases covering pCnt clamping, paramname length guards,
snprintf boundary, keyParams overflow check, and comma-prefix
for subsequent params.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 18:35:43 +01:00