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

request: json_init_library #540

Closed
dorssel opened this issue Feb 12, 2020 · 5 comments
Closed

request: json_init_library #540

dorssel opened this issue Feb 12, 2020 · 5 comments

Comments

@dorssel
Copy link

dorssel commented Feb 12, 2020

Many libraries allow overriding malloc, realloc, and free by (optionally) calling an initialization function. One of the use cases is to securely zeroize sensitive buffers. Currently, json-c uses platform malloc and free, which leaves all kinds of data (think: passwords) on the heap.

I suggest to use new functions json_malloc etc. throughout the library, which default to malloc etc., but which can be set to user provided functions (only upon initialization). Currently, json-c also uses strdup, which could be replaced by an internal function that implements it using the new json_malloc.

@hawicz
Copy link
Member

hawicz commented Feb 13, 2020

If we're going to go through the trouble of changing every memory allocation, it would be worthwhile to also use a type-specific slab allocators for the struct json_object's, struct array_list's, struct lh_table's, etc... Then again, that's a rather more significant change.

As for zeroizing sensitive buffers, if you're worried about that then it seems that merely changing the allocator used by json-c would be insufficient, as you'd be likely to have other allocations in your program that might have worthwhile-to-be-wiped content, in which case you should just replace malloc, free, etc... for the entire process.

In short, I'm not actually convinced that overriding library-specific memory allocation in this way is worthwhile.

@dota17
Copy link
Member

dota17 commented Feb 13, 2020

@hawicz As you said, slab allocator is suitable for the fixed-size struct/object which is scheduled frequently indeed. It is a good optimization direction. I will try to implement this function 0.0.
Using malloc/free will casue sensitive data leak. And malloc is not good func which also brings memory leak. In short, rewrite malloc/free is complicated and we shouldconsider it carefully.

@hawicz
Copy link
Member

hawicz commented Feb 14, 2020

@dota17, before implementing anything a change like that is worth discussing in more detail. If you have some ideas about an existing allocator to bring in to json-c, please mention it on the json-c Google group, or in a separate github issue.

@dota17
Copy link
Member

dota17 commented Feb 17, 2020

@hawicz ok, I got it!

@hawicz
Copy link
Member

hawicz commented Jul 4, 2020

I don't think there's anything to be done for this, so I'm closing it.

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

No branches or pull requests

3 participants