Skip to content
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

change OpaqueAttribute's _typeName field to be std::string #429

Merged
merged 1 commit into from
Jul 12, 2019

Conversation

cary-ilm
Copy link
Member

@cary-ilm cary-ilm commented Jul 9, 2019

SonarCloud considers strcpy() a vulernability. strcpy() was used only in OpaqueAttribute, whose type name was stored as Array. I changed the type to std::string. I suspect this simply dates to a time before std::string was commonly used.

Also, it appears that nothing in the test suite validated opaque attributes, which hold values read from a file when the attribute type is not known. I added a test to validate the behavior, which also validates that the typeName() works when implemented with std::string instead of Array.

Signed-off-by: Cary Phillips cary@ilm.com

…aqueAttribute, whose type name was stored as Array<char>. I changed the type to std::string. I suspect this simply dates to a time before std::string was commonly used.

Also, it appears that nothing in the test suite validated opaque attributes, which hold values read from a file when the attribute type is not known. I added a test to validate the behavior, which also validates that the typeName() works when implemented with std::string instead of Array<char>.

Signed-off-by: Cary Phillips <cary@ilm.com>
Copy link
Contributor

@meshula meshula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, but it did raise some questions.

@@ -76,7 +74,7 @@ OpaqueAttribute::~OpaqueAttribute ()
const char *
OpaqueAttribute::typeName () const
{
return _typeName;
return _typeName.c_str();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly this is unsafe, but the behavior is the same as before. It's interesting that Sonar doesn't spot it, as one would image returning c_str() is a smell the same strcpy is....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. strcpy() is a vulnerability because of the potential for buffer overflow, but SonarCloud does not regard c_str() as a vulnerability.

private:

Array<char> _typeName;
std::string _typeName;
long _dataSize;
Array<char> _data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another funny one, char is a signed value, and has a sizeof(1) and a bitsize of CHAR_BIT. I wonder if now is an opportunity to make _data an Array of std::uint8_t?

@cary-ilm cary-ilm merged commit 29d18b7 into AcademySoftwareFoundation:master Jul 12, 2019
@cary-ilm cary-ilm deleted the strcpy branch July 12, 2019 22:06
@cary-ilm cary-ilm added this to the v2.4.0 milestone Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants