- 
                Notifications
    You must be signed in to change notification settings 
- Fork 929
Improving opal_pointer_array bounds checking. #709
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
Conversation
| @bosilca any thoughts on this? Given that we do use pointer arrays in the critical path (IIRC), I suppose we could use opal_unlikely here or change to an assert. This is motivated by the code checking going on inside Intel, and the checker is barking because of the potential error if a negative index is given. | 
| @hjelmn any thoughts on this? | 
| Shouldn't we just make the index argument an unsigned int? This would cause a negative number to trigger the  | 
| @hjelmn: we could make it an unsigned int, however, this would require quite a few more changes.  The  | 
| @avilcheslopez you make a good point about the return code. We would need some way of returning an error, and the negative index was an easy one to check. Only other option would be to alter the param list so the index was returned in a pointer there, and then the return code can be an OPAL_ERR_foo. But that would again involve changing all the current usages, and that would be annoying. So I think your approach makes the most sense, though we may want to switch to an assert for performance (or at least an OPAL_UNLIKELY). | 
| @avilcheslopez taking another quick glance at the overall code, I think I'd suggest changing these to an assert. We should never see negative indices in practice, which means it was likely to be a programming error. So doing an assert that let's the developer stack trace the problem might be the best solution. | 
| @rhc54: makes sense. Unless anyone else has any input on this, I'll go ahead and change it to use asserts instead. | 
| I would argue that using the OPAL_UNLIKELY is the most clean way to handle this as it will allow us to maintain most of the performance of the original code while still having error checks. | 
| Test FAILed. | 
    
      
        1 similar comment
      
    
  
    | Test FAILed. | 
| @avilcheslopez I don't know if you've clicked through the "Details" links on the CI block at the bottom of the PR, but they're showing build failures like this: Perhaps you're missing a .h file...? | 
| asserts are noops in optimized builds so they are probably fine here. | 
| I don't have a strong opinion here either way -- I agree that passing a negative value is likely a programmer error, and so therefore an  With Intel chip branch prediction these days, I think the OPAL_UNLIKELY makes the penalty asymptotically approach zero. Also, in the  In the  @avilcheslopez Can you please squash these two commits down to one? In short: please squash into 1 commit, and then I think it's fine to merge to master. | 
| @jsquyres: awesome, will do! Thanks! | 
| @jsquyres: done! | 
Improving opal_pointer_array bounds checking.
OPAL_UNLIKELY).
udcm: fix bugs
This is basically just guarding against negative indexes.
For opal_pointer_array_get_item(), the code documentation specifies that NULL should be returned on error, so I simply expanded the check in the initial "if" statement to check for a negative index.
For opal_pointer_array_set_item(), the code documentation specifies that (-1) should be returned on error, so I added an "if" statement to check for a negative index. I noticed the assert instruction to guard against a NULL array and was wondering if this should be used to guard against a negative index instead, but figured returning an error was more consistent with the code documentation and more consistent with opal_array_get_item()'s behavior.
If this is not the appropriate fix, I would be more than happy to make the necessary changes.