Commit Graph

11 Commits

Author SHA1 Message Date
Levi Neely 874e25f11b
Fix pcl-zqv.4.2: protocol parsing and buffer safety in prpc/papi (#348)
prpc.c:
- on_request: fix total_size computation. The original formula
  sizeof(uint32_t)+sizeof(uint64_t)+response->length had two bugs:
  (1) sizeof(uint32_t)+sizeof(uint64_t)=12 but offsetof(rpc_message_t,value)=16
  due to struct alignment padding between the uint32_t type and uint64_t length
  fields; and (2) respond() was storing full message size in response->length,
  double-counting the header. Fix: use offsetof(rpc_message_t,value)+response->length,
  consistent with readResponse() in rpcclient.cpp which reads a fixed header_size
  of offsetof(rpc_message_t,value) bytes then reads msg->length payload bytes.
- respond: store payload length only in response->length (value_length+1),
  not full message size, to match the client protocol expectation.
- prpc_init: add null check on malloc return value.
- prpc_register: restore old handler table and return -1 if prpc_init fails.

papi.c:
- papi_result_thread: add missing MAX_API_RESPONSE_SIZE guard (present in
  papi_result but absent here), preventing server-controlled unbounded malloc.
- papi_result, papi_result_thread: add null checks on malloc before passing
  pointer to psock_readall.
- papi_result_async: add MAX_API_RESPONSE_SIZE check and malloc null check
  on reader->respsize path.
- calc_ret_len: add _NEED_DATA(1) guard before ARRAY and HASH while-loop
  conditions; empty containers with datalen=0 caused out-of-bounds read.

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 19:02:01 +01:00
Levi Neely c9bb7685b7
Add POVERLAY_BUFSIZE bounds check in prpc.c read loop (#322)
RPC commands tested, sync list works
2026-03-03 15:49:18 +01:00
Levi Neely 0ae4882ada
Fix integer overflow in prpc.c response->length calculation (#321)
RPC commands tested, daemon works
2026-03-03 15:46:39 +01:00
Levi Neely 3240c033bb
Fix use-after-free: heap-allocate socket fd for RPC threads (#314)
RPC commands tested and working
2026-03-03 15:08:29 +01:00
Levi Neely 87ab65b68c
Fix integer underflow in prpc.c handler dispatch (#306)
cbidx = request->type - 20 computed before checking lower bound.
If request->type < calbacks_lower_band, cbidx wraps to large value
causing out-of-bounds array access.

Move bounds check before subtraction and use calbacks_lower_band
instead of hardcoded 20.

Fixes GH #235

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
2026-03-03 12:37:13 +01:00
Levi Neely 6994a3cac9
102 create a psql namespace (#142)
* another stupid macro gone

* more stupid macros gone. moved util functions from plibs to putil

* remaining plist and ptask functions moved to appropriate namespaces

* dead code beleted!

* bugfixes

* move sql functions to psql.c

* move sort functions into ppagecache

* psql namespace

* change plibs.h include to pdbg.h

* cleanup includes
2025-03-18 19:52:15 +01:00
Levi Neely 9014edb99a
98 create a pdbg namespace (#139)
* pdbg split from plibs
* pdbg namespace
* add SSLDBGLVL build option
2025-03-13 20:28:09 +01:00
Levi Neely 9da561c767
131 remove custom memory management wrappers (#137)
* psync_free removed

* psync_malloc removed

* psync_realloc removed

* remove dead code

* remove pmemlock

* remove dead code
2025-03-11 22:27:30 +01:00
Levi Neely ce6033fe95
130 use trustworthy location for log and socket (#134)
* trustworthy location for log and socket
- socket in => $HOME/.pcloud/prpc.sock (mode 0600)
- debug log => $HOME/.pcloud/debug.log
* documentation updates
2025-03-11 19:03:58 +01:00
Levi Neely f437fe840e
prpc namespace and api cleanup (#122)
* prpc namespace and api cleanup
2025-03-09 17:13:35 +01:00
Levi Neely 1106028eba
WIP: Decompose namespaces and other cleanup (#94)
* papi namespace, remove some transient dependencies

* ptask namespace and cleanup

* pcache namespace and cleanup

* refactor pcallbacks into pqevent and ptevent

* pcryptofolder namespace and cleanup

* pcryptofolder missed a rename

* pdeflate namespace and cleanup

* pcrypto namespace

* pcrypto cleanup

* pcrypto consistency

* pcrypto more consistency

* pdevmon namespace and cleanup

* pdiff namespace

* pdownload namespace and cleanup

* pstatus namespace and cleanup

* pfileops namespace, fix header inlining abuse

* pfoldersync API, start chipping away at the psynclib monster

* pfscrypto namespace

* plocks namespace

* pnotify namespace

* pnotify formatting

* prpc namespace (got rid of confusing "overlay")

* pp2p namespace and cleanup

* ppagecache namespace

* ppassword namespace

* ppathstatus namespace

* prunratelimited => prun with throttling

* pscanner.c => psuggest namespace

* ptimer namespace

* ptools namespace (move to putil namespace someday)

* ptree namespace

* moved public link definitions into publiclinks.h, no clear namespace here though...

* pupload namespace

* formatting

* pcrc32c namespace
2025-03-01 22:21:54 +01:00