-
Notifications
You must be signed in to change notification settings - Fork 66
hardening: negative snprintf return values #182
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,8 +300,9 @@ gensalt_sunmd5_rn (unsigned long count, | |
|
|
||
| assert (count != 0); | ||
|
|
||
| size_t written = (size_t) snprintf ((char *)output, o_size, | ||
| "%s,rounds=%lu$", SUNMD5_PREFIX, count); | ||
| int written = snprintf ((char *)output, o_size, | ||
| "%s,rounds=%lu$", SUNMD5_PREFIX, count); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an actual
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fweimer-rh might be extremely unlikely, but things may break elsewhere and it is legit for To be honest, I don't know. Is there some good practice about how paranoid and double-checking is it worth to be (vs. not complicating the code)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fweimer-rh I would like to hear and follow your opinion. Shall we be more paranoid and expect that |
||
| assert (written > 0); | ||
|
|
||
|
|
||
| write_itoa64_4(output + written + 0, rbytes[2], rbytes[3], rbytes[4]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,8 +60,12 @@ gensalt_sha_rn (char tag, size_t maxsalt, unsigned long defcount, | |
| written = 3; | ||
| } | ||
| else | ||
| written = (size_t) snprintf ((char *)output, output_size, | ||
| "$%c$rounds=%lu$", tag, count); | ||
| { | ||
| int w = snprintf ((char *)output, output_size, | ||
| "$%c$rounds=%lu$", tag, count); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise I believe this invocation cannot fail. |
||
| assert (w > 0); | ||
| written = (size_t) w; | ||
| } | ||
|
|
||
| /* The length calculation above should ensure that this is always true. */ | ||
| assert (written + 5 < output_size); | ||
|
|
||
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.
there's another one above (L156)
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.
I only looked in the ones that are casted to
size_t, but you are right, it might make sense to go through allsnprintfcalls and make sure return value is checked for negativity.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.
I think the iffiness is slightly above:
Shouldn't this be bounded to a reasonable value? If I read the sources correctly, it currently isn't, although the documentation comment suggests it can be at most 64? Then the
snprintfbelow cannot fail withEOVERFLOW(or otherwise) anymore.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.
@fweimer-rh thanks for looking, I'll check.