Enlarge _oid2txt buffer to handle larger OIDs#3612
Conversation
|
@frasertweedale, thanks for your PR! By analyzing the history of the files in this pull request, we identified @alex, @reaperhulk and @intgr to be potential reviewers. |
|
It looks like you forgot to |
|
|
5101e7a to
f3f77f9
Compare
|
@reaperhulk whups, thanks! test-vectors.rst update imminent. |
f3f77f9 to
2f3c2da
Compare
|
@stevepeak we appear to have hit a bug of some sort - the Changes page for this diff isn't showing the actual source, just a blank space: |
|
Cool :) Nice edge case. I'll review 👍 |
|
@stevepeak thanks, we appreciate it! |
|
Don't merge this; better fix coming. |
The OpenSSL manual recommends a buffer size of 80 for OBJ_oid2txt: https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values. But OIDs longer than this occur in real life (e.g. Active Directory makes some very long OIDs). If the length of the stringified OID exceeds the buffer size, allocate a new buffer that is big enough to hold the stringified OID, and re-do the conversion into the new buffer.
2f3c2da to
effeb60
Compare
|
Is it possible to call |
|
On Sun, May 28, 2017 at 07:18:22PM -0700, Alex Gaynor wrote:
Is it possible to call `OBJ_obj2txt` with a `NULL` buffer to get the size?
This works. The downside is that we compute the conversion for the
whole OID twice, every single time.
With the first run using an 80-byte buffer we compute the conversion
only once in the overwhelming majority of cases.
Your call.
|
|
I feel like the correct answer is "let's benchmark!", but that seems like way too much work to ask you to do for what should be simple. @reaperhulk or I will review as-is I think. |
| # alloc a big-enough buffer and go again. | ||
| res = backend._lib.OBJ_obj2txt(buf, buf_len, obj, 1) | ||
| if res > buf_len - 1: # account for terminating null byte | ||
| buf_len = res + 1 |
There was a problem hiding this comment.
The fix is not sufficient. OBJ_obj2txt(buf, buf_len, obj, 1) does not return the actual required buffer size. You have to call the function with NULL buffer to make it calculate the correct size: OBJ_obj2txt(NULL, 0, obj, 1).
There was a problem hiding this comment.
(This is not accurate, a later tiran comment shows that it does return required buffer size)
| buf_len = 80 | ||
| buf = backend._ffi.new("char[]", buf_len) | ||
|
|
||
| # 'res' is the number of bytes that *would* be written if the |
There was a problem hiding this comment.
This is maybe not correct. More testing needed. Don't merge.
There was a problem hiding this comment.
(Confirmed that this is correct in a later comment by tiran)
|
Your code was correct. It looks like I screwed up while I was adopting your patch for CPython. The ssl module calls test caseoutput |
|
@tiran thanks for the update 👍 |
reaperhulk
left a comment
There was a problem hiding this comment.
this approach is fine by me
|
@alex if you have no objections I'll merge this shortly so it can be in 1.9. |
|
I haven't reviewed, but if you've reviewed I'm sure it's fine.
…On Mon, May 29, 2017 at 5:32 PM, Paul Kehrer ***@***.***> wrote:
@alex <https://github.com/alex> if you have no objections I'll merge this
shortly so it can be in 1.9.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3612 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAADBMeRupZbA_CbhBXPUkiptyAntdDLks5r-zl7gaJpZM4NnHdW>
.
--
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: D1B3 ADC0 E023 8CA6
|

The OpenSSL manual recommends a buffer size of 80 for OBJ_oid2txt:
https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values.
But OIDs longer than this occur in real life (e.g. Active Directory
makes some very long OIDs). Use a more conservative buffer size of
256 to prevent crashes if the length of the stringified-OID exceeds
80 characters.