JA: Invalid memory usage fixes and a some minor stuff.#785
Conversation
* Add NO_SANITIZE_ADDRESS macro that allows to pass attribute * Add NO_SANITIZE attribute to Z_IsFromZone and VM_DllSyscall functions because they are doing nasty things with memory.
Even though vec3_t is an array of 3 elements, sizeof(vec3_t) returns correct value. So no need to allocate 3x space and copy it 3x times.
|
I'm not sure about the bits with color ('Color always have alpha' commit) and would like to hear comments from you about it. |
|
P.S. I also think that at some point you should get rid of ALL false-positives here. Especially the one within Z_IsFromZone is pissing me off. |
|
I occasionally chuck on |
|
Actually I was surprised that I need to fix only two places for MP to work. About last commit - after 10-15 minutes of playing with bots I've got: Basically I've done the same as strncpy in glibc do, but in a different order. Memcpy's behavior is defined in C and C++ standard for overlaping strings (as far as I remember) |
|
@Razish well, with this set of patches I was able to play two levels in single player and play 30 minutes with bots in multiplayer, while the game was compiled with Address Sanitizer. |
|
I'll also test Jedi Outcast with address sanitizer, but all the fixes for JO will go to another PR (along with the fixed I've already made in my fork for it). |
|
That's still not all, cause now I'm getting one "INVALID READ" with following trace and I can't find out why: INVALID READ happens when it's getting hitLoc[hitEntNum[numHitEnts]] Found out that hitEntNum [numHitEnts] for some reason was 350. |
|
I've also added SIGFPE fix to this PR, cause it's really simple and also happens while I was playing a game, testing other fixes. Though it's not related to sanitize-address. That's I think all I was able to find during quick playing with AddressSanitizer in JASP and JAMP. |
|
Rejecting changes to Q_strncpyz. It is up to the user to not use it in overlap cases. Also strnlen is not standard, even if it is supported by gcc, clang and msvc. |
|
@ensiform well, what's behavior of strncpy in overlapping cases? Because JA Engine have them. The thing is that behavior of compiles can be different in that case, and for example on Windows, Mac OS X and Linux you may get 3 different behaviors of something (I really haven't investigated what was the strings it tried to copy, cause ASAN won't provide that info). So it's either you should make Q_strncpyz overlapping-safe or fix all cases when it happens. If you decide to ignore it and leave as-is you most likely will get platform dependent bugs. |
We assume that color is rgba, but for flares a was garbage
We are have only sTemp - strlen(sTemp) bytes left, but we are copying up to sizeof(sTemp) bytes which will overwrite strlen(sTemp) bytes of memory in some rare cases.
Same thing as in single player
|
You fix all areas where it happens. They've been fixed last I checked as you didn't point any specific ones out. |
And this sometimes (rarely) happens. AddressSanitizer says on this 'strncpy-param-overlap'.
|
Well, ok, I'll revert srncpyz changes, and will just open new bugs about all areas where I get overlapping strings then, cause if they are not accidentally fixed by this PR, there are some, cause I've definitely got some errors related to that during playing the game. |
|
This is how its been fixed in the past. |
|
Do you really need to open bugs constantly for every single thing it finds instantly? |
|
@ensiform well, if you have another way to tell that there is a bug, and that's debug info I was able to get - then tell me. I'm opening bug per thing I don't know how to fix myself. Things that I know how to fix, I've fixed in this PR. |
|
Well try to hold off until you can verify they're actually bugs I guess? I'm still not convinced there isn't a major memory issue causing a lot of extra problems. NaN issues are already posted for example, just not on the first page. |
|
@ensiform ok. |
|
Gr... Looks like I've deleted some of useful commits. I'll restore them tomorrow and also will get rid of Q_strncpyz. |
Please don't merge it for now. This PR is intended to track and discuss bad things I've found during compiling game with memory sanitize enabled.