Skip to content

lib/tapi_job: fix send length: use str->len, not str->size#11

Open
okt-konst wants to merge 1 commit into
ts-factory:mainfrom
okt-konst:up/tapi-job-send-len
Open

lib/tapi_job: fix send length: use str->len, not str->size#11
okt-konst wants to merge 1 commit into
ts-factory:mainfrom
okt-konst:up/tapi-job-send-len

Conversation

@okt-konst

Copy link
Copy Markdown
Collaborator

tapi_job_send() was passing str->size (the allocated buffer capacity) to
rpc_job_send() instead of str->len (the actual content length).
te_string_reserve() rounds the buffer up to growth-factor multiples, so
str->size is always >= str->len and often much larger.

The excess bytes (zeros beyond the NUL terminator) were serialized into the
RPC payload and written to the process's stdin pipe. A single send worked
by accident: the process reads line-by-line and the trailing NULs appeared
after the newline. On the second send those buffered NULs accumulated in
the pipe ahead of the new data, prepending garbage to the request, breaking
any caller that sends more than one message to a running process.

Fix: pass str->len so only the actual content is transmitted.

tapi_job_send() was passing str->size (the allocated buffer
capacity) to rpc_job_send() instead of str->len (the actual
content length).  te_string_reserve() rounds the buffer up
to growth-factor multiples, so str->size is always >= str->len
and often much larger.

The excess bytes (zeros beyond the NUL terminator) were
serialized into the RPC payload and written to the process's
stdin pipe.  A single send worked by accident: the process
reads line-by-line and the trailing NULs appeared after the
newline.  On the *second* send those buffered NULs accumulated
in the pipe ahead of the new data, prepending garbage to the
request, breaking any caller that sends more than one message
to a running process (e.g. pyte.remote's JSON protocol).

Fix: pass str->len so only the actual content is transmitted.

Signed-off-by: Konstantin Ushakov <kushakov@oktet.co.il>
@okt-konst okt-konst marked this pull request as ready for review July 6, 2026 22:53
@okt-konst

Copy link
Copy Markdown
Collaborator Author

@ol-arteman @arybchik could you please review?

@okt-konst okt-konst requested review from arybchik and ol-arteman July 6, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants