sid-project / sid

Storage Instantiation Daemon
https://sid-project.github.io
12 stars 5 forks source link

Unaligned Variable accesses. #131

Closed bmarzins closed 1 year ago

bmarzins commented 1 year ago

I'm not sure how much of an issue this is, but there are many places in the code where SID is accessing a variable stored in a buffer that is not at a size aligned address. In the code I wrote for 9e2e3f09f7a3a9af1b6179019510f1ebb3581896 SID is even dereferencing pointers from in the buffer (assuming that malloc always returns pointer size aligned memory, those should always be aligned). The traditional way to read from a non-aligned variable it to memcpy it to an aligned variable, like this:

-               key_size             = *((size_t *) p);
+               memcpy(&key_size, p, sizeof(key_size));

I'm not sure if we support any architectures where accessing unaligned variables will do anything worse than slowing things down, but if you want, I can go through and clean these up. Regardless, I am going to send a patch to copy out the rollback structures before using them, since now that I think about it dereferencing pointers from a packed structure just seems icky.

prajnoha commented 1 year ago

Sure, we could fix all the occurrences, to be sure it's all correct.

prajnoha commented 1 year ago

Fixed by commits 0fa2ca0f8d848b61d8f463b016dbd829c8156efe .. 5345b861fe9116ba432d4f6b48fa1645488cb319 and b7ad3199880f43bd246f162cb5fa29959db679b2 .. 39d25ca4648bba4f00406fa4e4532b7b3c54ccaf.