-
Notifications
You must be signed in to change notification settings - Fork 621
Remove deprecated X509_NAME_get_text_by_NID() #2389
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: master
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1060,14 +1060,18 @@ static const char *getSubjectEntry(X509 *x509, int nid) | |||||||
| return nullptr; | ||||||||
|
|
||||||||
| // TODO: What if the entry is a UTF8String? See X509_NAME_get_index_by_NID(3ssl). | ||||||||
| const int nameLen = X509_NAME_get_text_by_NID( | ||||||||
| X509_get_subject_name(x509), | ||||||||
| nid, name, sizeof(name)); | ||||||||
|
|
||||||||
| if (nameLen > 0) | ||||||||
| return name; | ||||||||
| const auto nm = X509_get_subject_name(x509); | ||||||||
|
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. Please test |
||||||||
| int pos = -1; | ||||||||
| pos = X509_NAME_get_index_by_NID(nm, nid, pos); | ||||||||
|
Comment on lines
+1065
to
+1066
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. If possible, please make
Suggested change
|
||||||||
| if (pos < 0) { | ||||||||
| debugs(83, 3, (pos == -2 ? "Invalid" : "Missing") << " SSL certificate subject name"); | ||||||||
|
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. In current PR code, negative
Suggested change
Converting |
||||||||
| return nullptr; | ||||||||
| } | ||||||||
|
|
||||||||
| return nullptr; | ||||||||
| const auto str = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(nm, pos)); | ||||||||
|
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. Similar lack of error checking concerns apply here, especially since |
||||||||
| xstrncpy(name, reinterpret_cast<const char *>(ASN1_STRING_get0_data(str)), sizeof(name)); | ||||||||
|
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.
To avoid out of bound reads, we should at least be using We should return nil instead of truncated names when the N.B. AFAICT, "get0" in OpenSSL function names means something like "raw access to an internal buffer" rather than a "c-string". |
||||||||
| return (*name ? name : nullptr); | ||||||||
| } | ||||||||
|
|
||||||||
| const char *Ssl::CommonHostName(X509 *x509) | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -874,7 +874,14 @@ ssl_get_attribute(X509_NAME * name, const char *attribute_name) | |
| debugs(83, DBG_IMPORTANT, "WARNING: Unknown SSL attribute name '" << attribute_name << "'"); | ||
| return nullptr; | ||
| } | ||
| X509_NAME_get_text_by_NID(name, nid, buffer, sizeof(buffer)); | ||
| int pos = -1; | ||
| pos = X509_NAME_get_index_by_NID(name, nid, pos); | ||
| if (pos < 0) { | ||
| debugs(83, 3, (pos == -2 ? "Invalid" : "Missing") << " SSL attribute name '" << attribute_name << "'"); | ||
| return nullptr; | ||
| } | ||
| auto str = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, pos)); | ||
| xstrncpy(buffer, reinterpret_cast<const char *>(ASN1_STRING_get0_data(str)), sizeof(buffer)); | ||
|
Comment on lines
+877
to
+884
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. Please do not duplicate this non-trivial and error-prone code! Add and reuse an |
||
| } | ||
|
|
||
| return *buffer ? buffer : nullptr; | ||
|
|
||
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.
AFAICT, this comment (and the matching manual page text) were written for
X509_NAME_get_text_by_NID()call that this PR upgrades. The comment becomes misplaced in PR code -- it looks like it applies toX509_get_subject_name(), but it does not.The comment mentions but does not apply to
X509_NAME_get_index_by_NID()that official code did not have, but PR code has, causing additional confusion.The comment now applies to
ASN1_STRING_get0_data()call further below, I guess.Please move and adjust to address all these problems.