-
Notifications
You must be signed in to change notification settings - Fork 353
Ensure VERSION is NUL-terminated #213
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
Conversation
|
a less intrusive patch would be to use fprintf(stderr, "dumb-init v%.*s", VERSION_len, VERSION); |
|
It's an interesting idea, though it has one drawback - if someone needs to add a new piece of code that uses As a third option, how about keeping |
|
I would prefer the one line patch as I indicated, this tool has had very little maintenance and I doubt that a new use for |
The "%s" conversion specifier expects a NUL-terminated string. However, the VERSION variable does not contain a NUL-terminator, so formatting it using "%s" may lead to printing whatever happens to be in memory next to VERSION. Using "%*s" allows to specify how many characters to print, thus making sure we don't go off the array.
040188d to
7bb2fef
Compare
|
Sure. Rewrote the patch and force-pushed the branch. |
asottile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thanks for the fix! I think I won't release a new version just for this fix since as far as I understand this isn't causing issues in practice (due to automatic null byte padding around the constant?) but let me know if I'm misunderstanding the impact. |
|
Well, the only reason I spotted and patched this is because it did, in fact, cause issues in practice. ;) In the Fedora Linux distribution, we had issues with building the dumb-init package. It turned out that on the s390x architecture, while the program built fine, the test suite failed - on this particular arch, the |
|
Thanks for letting me know, I've released a v1.2.3 which contains this fix. |

The
VERSIONvariable is referenced in two places insidedumb-init.c: in theprint_help()function, and inparse_command(), when the--versionoption is passed:In both of these cases,
VERSIONis used as an argument tofprintf(), to be formatted with%s. The man page forfprintf(3)says this about the%sconversion specifier:However, the way
VERSIONis currently generated, it does NOT contain the terminating null byte.This patch changes the way
VERSION.his generated, to ensure thatVERSIONis a NUL-terminated string.