libopendkim: fix strlcpy destination size in dkim_diffheaders()#291
Open
thegushi wants to merge 1 commit into
Open
libopendkim: fix strlcpy destination size in dkim_diffheaders()#291thegushi wants to merge 1 commit into
thegushi wants to merge 1 commit into
Conversation
Pass MAXHEADERS (the actual allocation size of dkim_zdecode) as the strlcpy size argument instead of strlen(z) (source size). Using the source length silently truncates the copy by one character and suppresses the compiler warning incorrectly. Also fix the adjacent error message which reported strlen(z) bytes when MAXHEADERS bytes are actually allocated. Fixes trusteddomainproject#86.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #86.
The
strlcpycall indkim_diffheaders()was passingstrlen(z)(the source length) as the size argument instead of the destination buffer size.strlcpyexpects the size of the destination, so using the source length would silently truncate the copy by one character and is what triggers the compiler warning.The buffer is allocated with
MAXHEADERS(32768 bytes), so the correct size argument isMAXHEADERS.Also fixed the adjacent allocation error message which was reporting
strlen(z)bytes whenMAXHEADERSbytes are actually being allocated.Neither the original code nor the proposed patch in the issue was correct:
strlen(z)): copies at moststrlen(z) - 1characters, truncating by onestrlen(dkim->dkim_zdecode)): on freshly-allocated memory this isstrlen("") = 0, copying nothingMAXHEADERS, matching theDKIM_MALLOC(dkim, MAXHEADERS)on the line above