Skip to content

Secure alloc compile time #426

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

Closed
wants to merge 10 commits into from
Closed

Secure alloc compile time #426

wants to merge 10 commits into from

Conversation

dawesc
Copy link
Contributor

@dawesc dawesc commented Feb 17, 2016

Hi Chris, I hope all's well, here's a version of the secure allocator using typedefs in config similar to the way it's done with UInt; i've checked it in with 1 as secure allocator at the moment as i'd like to see what the regression test thought of it first of all. What would you prefer the default to be though?

Thanks again for your support on this,

Christopher

Christopher Dawes and others added 5 commits February 5, 2016 10:55
Merge jsoncpp latest changes to forked master
Merge jsoncpp latest changes to forked master
Before freeing data use memset in Value to 0
Use secure allocator globally when configured but leave as much backward
compatible as possible in the public interfaces (particularly asString
and Reader).
@@ -230,7 +230,7 @@ class JSON_API Value {

struct StringStorage {
unsigned policy_: 2;
unsigned length_: 30; // 1GB max
size_t length_: 30; // 1GB max
Copy link
Contributor

Choose a reason for hiding this comment

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

This could break binary compatibility. Was this necessary for compilation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi chris, sorry i changed it to make life easier but for backward compatibility you're right, i've fixed this

@cdunn2001
Copy link
Contributor

Whew! Tons of changes, but way less than in that previous monster PR.

@@ -572,6 +573,7 @@ Json::Value obj_value(Json::objectValue); // {}
void setComment(const char* text, size_t len);

char* comment_;
size_t len_;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to add another #ifdef around this

* Remove added instance variables when not secure
* Change to original types
* getCStringLength available in secure mode only
* asString now returns the secure version if compiled in secure mode
// If non-zero, the library zeroes any memory that it has allocated before
// it frees its
#ifndef JSON_USE_SECURE_MEMORY
#define JSON_USE_SECURE_MEMORY 1
Copy link
Contributor

Choose a reason for hiding this comment

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

0 by default -- at least until we measure the runtime/memory cost of using this allocator.... Oh, actually, since there are binary-incompatible changes, this will have to be 0 by default until version 2.0.0, and forever if the cost is significant.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll have to check whether the typedefs alter the symbols. If so, then we'll need to switch those all to macros (poor-man's template). Again, that's to ensure binary-compatibility. It's painful, but our unusual care for binary-compatibility is one reason why a distro like Debain includes JsonCpp.

@cdunn2001
Copy link
Contributor

In our defense, I'd like to state that none of us wrote this library. Baptiste, the primary author, had good reasons for everything at the time. We're now maintaining it and hopefully letting it evolve in a positive direction. So please excuse the oddities in implementation.

People were very skeptical when I added the string-prefixing, but it has proven invaluable.

I should have more time this weekend or next. I plan to accept the typedefs (or macros, if necessary). Then you can rebase with a much smaller pull-request.

Remove all the lengths on strings so that we use the memory already
allocated
It wasn't taking into account the length prefix
@dawesc
Copy link
Contributor Author

dawesc commented Feb 20, 2016

Thanks so much for all of this Chris, it's really very much appreciated all the effort you've put in on this. Christopher

@cdunn2001
Copy link
Contributor

Ok. This is looking pretty good. But I'm swamped this weekend. I'll rebase as soon as I can...

@cdunn2001 cdunn2001 self-assigned this Feb 21, 2016
@dawesc
Copy link
Contributor Author

dawesc commented Feb 21, 2016

I just wanted to re-iterate my thanks for all your support you've put in an amazing amount of time on this to help me get this through and it's thoroughly appreciated!

@cdunn2001 cdunn2001 mentioned this pull request Mar 6, 2016
@cdunn2001
Copy link
Contributor

Would you rebase to the JSONCPP_STRING branch and submit a new pull-request?

@dawesc
Copy link
Contributor Author

dawesc commented Mar 6, 2016

Hi Chris, I've squashed it to #436 #437.

Many thanks

Christopher

@dawesc dawesc closed this Mar 6, 2016
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.

2 participants