Skip to content

criu/log: properly handle truncated length from vsnprintf#2819

Merged
avagin merged 2 commits into
criu-devfrom
criu-log-sprintf-ret
Nov 12, 2025
Merged

criu/log: properly handle truncated length from vsnprintf#2819
avagin merged 2 commits into
criu-devfrom
criu-log-sprintf-ret

Conversation

@avagin

@avagin avagin commented Nov 11, 2025

Copy link
Copy Markdown
Member

vsnprintf does not always return the number of bytes actually written to the buffer.

If the output was truncated due to the buffer limit, the return value is the total number of bytes which WOULD have been written to the final string if enough space had been available.

This means we must cap the return value to the buffer size excluding the terminating null byte to correctly calculate the log entry size.

Fixes #2781

@avagin
avagin requested a review from Copilot November 11, 2025 23:17
@avagin
avagin marked this pull request as draft November 11, 2025 23:18
vsnprintf does not always return the number of bytes actually written to
the buffer.

If the output was truncated due to the buffer limit, the return value is
the total number of bytes which WOULD have been written to the final
string if enough space had been available.

This means we must cap the return value to the buffer size excluding the
terminating null byte to correctly calculate the log entry size.

Signed-off-by: Andrei Vagin <avagin@google.com>
@avagin
avagin force-pushed the criu-log-sprintf-ret branch from d138c94 to cdff770 Compare November 11, 2025 23:21
@avagin
avagin marked this pull request as ready for review November 11, 2025 23:41
@avagin
avagin requested review from kolyshkin and rst0git November 11, 2025 23:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@rst0git rst0git left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I was able to confirm that this change fixes the error in #2781

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kolyshkin kolyshkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more (minor) issue found.

Comment thread criu/log.c Outdated
Using sizeof(hdr) where hdr is a pointer gives the size of the pointer,
not the size of the structure it points to.

Reported-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
@avagin
avagin requested a review from Copilot November 12, 2025 05:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@avagin
avagin merged commit a1fd7e6 into criu-dev Nov 12, 2025
66 of 78 checks passed
@avagin
avagin deleted the criu-log-sprintf-ret branch November 12, 2025 06:36
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.

runc tests fail with criu-dev

4 participants