pcloudcc-lneely/pclsync
Levi Neely 7595c485bf
Fix bad-free heap corruption in ppathstatus and psyncer (#392)
* Fix bad-free heap corruption in ppathstatus and psyncer (#391)

Both ppathstatus.c and psyncer.c used bare free() via
ptree_for_each_element_call_safe to bulk-free tree nodes that were
allocated with pmem_malloc.  pmem_malloc prepends a pmem_header_t to
every allocation, so the returned pointer is an interior pointer to the
underlying glibc chunk.  Passing it to free() makes glibc read a garbage
size field from the pmem header and abort with "free(): invalid size".

This is the same class of bug fixed earlier in pintervaltree.c and
pfscrypto.c.  The crash manifests reliably with larger files because
more sync-queue and path-status churn occurs, increasing the likelihood
that one of these bulk-free paths is hit while a non-empty tree exists.

Fix: add free_folder_tasks_node() (ppathstatus.c) and
free_synced_down_folder() (psyncer.c) helpers that call pmem_free, and
use them as the ptree_for_each_element_call_safe callback in all three
affected call sites.

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

* Fix bad-free in pfs.c and ppagecache.c (pcl-26j)

Two more call sites passed bare free() as a callback to tree/list
traversal macros, but the nodes were allocated via pmem_malloc which
prepends a pmem_header_t. Freeing the data pointer directly skips the
header and corrupts the heap.

- pfs.c: ptree_for_each_element_call_safe on sectorsinlog used free()
  on psync_sector_inlog_t; replaced with free_sector_inlog_node() that
  calls pmem_free(PMEM_SUBSYS_OTHER, e).
- ppagecache.c: psync_list_for_each_element_call on request->ranges
  used free() on psync_request_range_t; replaced with
  free_request_range() that calls pmem_free(PMEM_SUBSYS_CACHE, range).

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

* Add unit and smoke tests for pcl-26j bad-free (ppagecache, pfs, psyncer)

Unit test (test_pcl26j_free): exercises all four fixed call sites —
psync_request_range_t, synced_down_folder, folder_tasks_t, and
psync_sector_inlog_t — using --wrap=malloc/free to verify that
pmem_free() passes the header pointer to free(), not the data pointer.
Includes a harness self-check that confirms bare free(data_ptr) is
detected. Would have failed against pre-fix code.

Smoke test (smoke-test-large-read.sh): builds pcloudcc with ASAN,
starts the daemon, streams a large file (>=50 MB) from the FUSE mount
to /dev/null to force multi-range psync_request_range_t allocation and
teardown via psync_pagecache_free_request, then scans the ASAN log for
any bad-free reports.

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-24 12:12:50 +01:00
..
debug Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
LICENSE reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
paccountevents.h reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
papi.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
papi.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pbusinessaccount.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pbusinessaccount.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcache.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pcache.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcommands.h Add authsave command to save authentication credentials (#389) 2026-03-11 22:23:09 +01:00
pcompiler.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
pcontacts.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pcontacts.h reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
pcrc32c.c 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
pcrc32c.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcrypto.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pcrypto.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcryptofolder.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pcryptofolder.h access pcryptofolder directly from pclsync_lib (#125) 2025-03-09 19:58:00 +01:00
pdatabase.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pdbg.c Add GitHub Actions CI workflow for unit tests (#379) 2026-03-10 17:48:42 +01:00
pdbg.h Fix pcl-0c1: make pdbg_runtime_level atomic (#343) 2026-03-03 20:08:18 +01:00
pdeflate.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdeflate.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pdevice.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdevice.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pdevmon.c fix compile errors (#155) 2025-05-15 19:14:57 +02:00
pdevmon.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pdiff.c Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
pdiff.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pdiff_helpers.c Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
pdiff_helpers.h Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
pdownload.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdownload.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
pfile.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pfile.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pfileops.c 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
pfileops.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pfolder.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pfoldersync.h move folder-related code from psynclib to pfolder 2025-04-18 15:23:50 +02:00
pfs.c Fix bad-free heap corruption in ppathstatus and psyncer (#392) 2026-03-24 12:12:50 +01:00
pfs.h Add lock ordering assertions in debug builds (#370) 2026-03-08 15:38:41 +01:00
pfs_helpers.c Testability refactor: extract helpers, add stress/send tests, ppagecache/pfs extraction (#383) (#385) 2026-03-11 19:24:39 +01:00
pfs_helpers.h Testability refactor: extract helpers, add stress/send tests, ppagecache/pfs extraction (#383) (#385) 2026-03-11 19:24:39 +01:00
pfs_internal.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pfscrypto.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pfscrypto.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsfolder.c Testability refactor: extract helpers, add stress/send tests, ppagecache/pfs extraction (#383) (#385) 2026-03-11 19:24:39 +01:00
pfsfolder.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsstatic.c Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsstatic.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfstasks.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
pfstasks.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pfstasks_internal.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pfstasks_tree.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
pfstasks_tree.h Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
pfsupload.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
pfsupload.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsupload_send.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
pfsupload_send.h Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
pfsxattr.c Migrate to FUSE 3.x API (#350) 2026-03-09 21:51:00 +01:00
pfsxattr.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pintervaltree.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pintervaltree.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
plibs.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plibs.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
plist.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plist.h Fix typo: rename psync_list_bulder_* to psync_list_builder_* (#302) 2026-03-03 12:23:16 +01:00
plocalnotify.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plocalnotify.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
plocalscan.c Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
plocalscan.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
plocalscan_helpers.c Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
plocalscan_helpers.h Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
plocks.c Add deadlock detection with timeouts (#364) 2026-03-08 11:55:25 +01:00
plocks.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pmem.c Bug fixes: heap-use-after-free in pmem_realloc, auto-create FUSE mountpoint (#374) 2026-03-10 13:01:53 +01:00
pmem.h Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pnetlibs.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pnetlibs.h 98 create a pdbg namespace (#139) 2025-03-13 20:28:09 +01:00
pnotify.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pnotify.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pp2p.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pp2p.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ppagecache.c Fix bad-free heap corruption in ppathstatus and psyncer (#392) 2026-03-24 12:12:50 +01:00
ppagecache.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ppagecache_helpers.c Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
ppagecache_helpers.h Phase 4 testability refactor: pdiff, plocalscan, ppagecache helper extraction (#386) 2026-03-11 20:35:05 +01:00
ppassword.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ppassword.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ppassworddict.h reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
ppath.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
ppath.h Musl fixes (#143) 2025-04-13 09:11:11 +02:00
ppathstatus.c Fix bad-free heap corruption in ppathstatus and psyncer (#392) 2026-03-24 12:12:50 +01:00
ppathstatus.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pqevent.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pqevent.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
prand.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
prand.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
prpc.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
prpc.h 130 use trustworthy location for log and socket (#134) 2025-03-11 19:03:58 +01:00
prun.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
prun.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
prunthrottled.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
prunthrottled.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pscanexts.h Appease the LSP server (#73) 2024-11-26 19:36:49 +01:00
psettings.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psettings.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pshm.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pshm.h #64 simplify messaging and #71 deserialize failed (#88) 2025-02-25 09:46:46 +01:00
psignal.c Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psignal.h Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psock.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psock.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
psql.c Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psql.h Fix pcl-10w: remove IS_DEBUG conditional from psql.h (#363) 2026-03-07 21:37:21 +01:00
psql_internal.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pssl.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pssl.h 98 create a pdbg namespace (#139) 2025-03-13 20:28:09 +01:00
psslcerts.h Add new pCloud SSL certificate fingerprint (#172) 2026-03-01 09:14:29 +01:00
pstatus.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pstatus.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
psuggest.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psuggest.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
psyncer.c Fix bad-free heap corruption in ppathstatus and psyncer (#392) 2026-03-24 12:12:50 +01:00
psynclib.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psynclib.h Fix pcl-r0j: rename psync_delete_sync_by_folderid to pfolder_delete_sync_by_id (#361) 2026-03-07 19:54:21 +01:00
psys.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psys.h Fix pcl-ivv: remove weak attribute from debug hooks (#362) 2026-03-07 20:18:51 +01:00
ptask.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
ptask.h 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
ptask_free.c Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
ptask_free_internal.h Add testability infrastructure: unit tests, extracted modules, CI integration (#381) 2026-03-11 07:52:35 +01:00
ptevent.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptevent.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ptimer.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptimer.h 98 create a pdbg namespace (#139) 2025-03-13 20:28:09 +01:00
ptools.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptools.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ptree.c 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
ptree.h Fix ptree_for_each_element loop termination condition (#319) 2026-03-03 15:29:44 +01:00
ptypes.h Appease the LSP server (#73) 2024-11-26 19:36:49 +01:00
publiclinks.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
publiclinks.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pupload.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pupload.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
putil.c Add GitHub Actions CI workflow for unit tests (#379) 2026-03-10 17:48:42 +01:00
putil.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
sockets.h Merge pclsync and poverlay_linux (#46) 2024-08-18 15:09:21 +02:00