Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: check for snprintf truncation #1595

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

eriksjolund
Copy link
Contributor

No description provided.

Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
@kwilczynski
Copy link
Member

/approve
/lgtm

@@ -1930,7 +1930,7 @@ find_executable (const char *executable_path, const char *cwd)
it = ".";

len = snprintf (path, PATH_MAX, "%s/%s", it, executable_path);
if (len == PATH_MAX)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for len to be > PATH_MAX? snprintf would ensure it is not, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, at least that is how I understand the man page
https://man7.org/linux/man-pages/man3/fprintf.3p.html#RETURN_VALUE

This PR matches this example:

if (UNLIKELY (n >= max_len))

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe giuseppe merged commit f12b2da into containers:main Oct 29, 2024
57 checks passed
@eriksjolund eriksjolund deleted the check-for-truncation branch October 29, 2024 21:09
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.

4 participants