-
Notifications
You must be signed in to change notification settings - Fork 547
Fix string decryption race #80
Comments
Please rephrase your question with proper english |
Well, now when we enable string encryption of function, we are creating an encrypted global variable for each function where it used. Then, when we decrypting variable at first time, we can get into the thread race if several threads step into this function. As a result, string will be corrupted. My question is: why can`t wee just creating two global variables for one string, decrypting first variable into the second, and then use second. We allocate more memory for global variables, but we avoid possible crashes of a program. In my case crash is worst case. Sorry for my bad english. |
For example, my implementation: |
Right, this is a well documented feature. This will probably stay like that in forseeable future for the following reasons:
As a result, the suggested solution in this case is to add your own locking mechanism in Application code |
That being said, it's pretty trivial to add |
If we use two global variables, a thread race is possible only if one of the threads modifies a variable in the program logic, it is much better than an uncontrolled thread race on decryption. Global strings are often used for reading. |
I do not think that this is a smart solution, but the use of any lock entails a binding to the api of the operating system. And lock locking will occur on every function call. Moreover, there will be a race to initialize the mutex. You can of course embed mutex initialization at compile time, but how many mutex formats can you support this way? You can certainly implement your own spinlock, but it will look like a dirty hack. |
Thank you for your attention. In any case, for my own purposes I have to use my solution (: |
Ah I see, noted as future enhancement |
Thank you for your time. I already wrote the code, but I tested it only on Linux. Do I need to make a pull request for your review? |
Yes please |
Thanks |
Hi, then we use encryption of strings, a race condition is possible cause we use one global variable for decryption. So why can't we use two global variables of the same length and decrypt the string into a second variable, and then use it?
The text was updated successfully, but these errors were encountered: