This repository was archived by the owner on Mar 10, 2026. It is now read-only.
Avoid truncation when encoding Kerberos token#5435
Closed
hansmi wants to merge 1 commit into
Closed
Conversation
The "httpEncode64_2" function appends padding (0-3x "="). The buffer
size calculation in "_cupsSetNegotiateAuthString" did the calculation
wrongly and would have a buffer overflow for tokens of size (N * 4)
+ 1 and (N * 4) + 2. With this change the buffer size is computed
correctly.
Proof-of-concept in Python:
$ python <<'EOF'
import base64
def calc(c):
raw = c * "A"
enclen = len(base64.b64encode(raw))
origlen = len(raw) * 4 / 3 + 1
fixedlen = ((4 * len(raw) / 3) + 3) & ~3
print
print "input len = ", c
print "encoded len =", enclen
print "orig len = ", origlen, ("(bad)" if enclen > origlen else "")
print "fixed len = ", fixedlen, ("(bad)" if enclen > fixedlen else "")
print "waste = ", fixedlen - enclen
for i in range(7): calc(i)
EOF
Output:
---
input len = 0
encoded len = 0
orig len = 1
fixed len = 0
waste = 0
input len = 1
encoded len = 4
orig len = 2 (bad)
fixed len = 4
waste = 0
input len = 2
encoded len = 4
orig len = 3 (bad)
fixed len = 4
waste = 0
input len = 3
encoded len = 4
orig len = 5
fixed len = 4
waste = 0
input len = 4
encoded len = 8
orig len = 6 (bad)
fixed len = 8
waste = 0
input len = 5
encoded len = 8
orig len = 7 (bad)
fixed len = 8
waste = 0
input len = 6
encoded len = 8
orig len = 9
fixed len = 8
waste = 0
---
Contributor
|
Changing the title to reflect the issue - httpEncode64_2 won't overflow, it will truncate. |
michaelrsweet
added a commit
that referenced
this pull request
Nov 14, 2018
michaelrsweet
added a commit
that referenced
this pull request
Nov 14, 2018
Contributor
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The "httpEncode64_2" function appends padding (0-3x "="). The buffer
size calculation in "_cupsSetNegotiateAuthString" did the calculation
wrongly and would have a buffer overflow for tokens of size (N * 4)
+ 1 and (N * 4) + 2. With this change the buffer size is computed
correctly.
See commit message for detailed calculation.