Fix nodes and links bounds check. #474
                
     Merged
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
For example, consider the following in nodes.cpp:
hlsdk-portable/dlls/nodes.cpp
Lines 1413 to 1416 in 13086d3
hlsdk-portable/dlls/nodes.cpp
Lines 2651 to 2655 in 13086d3
For nodes,
ishould always be less thanm_cNodesand less thanm_cLinksfor links. Assuming it's the case, ifm_cNodes = 11thenm_pNodes[11]should be invalid. Ifm_cLinks = 18thenm_pLinkPool[18]should also be invalid.Methods
Node(int i)andLink(int i)check whetheriis a valid index.hlsdk-portable/dlls/nodes.h
Lines 219 to 220 in 13086d3
hlsdk-portable/dlls/nodes.h
Lines 228 to 229 in 13086d3
In the case of
Node(int i), the last out of bound check isi > m_cNodes. Ifm_cNodes = 11andi = 11, it shouldn't be valid but still passes. The same applies toLink(int i).Quick test
ito each of the following values and assert:Note:
m_cNodes = 11andm_cLinks = 18in c2a5a.Node(int i)
Link(int i)
Changing to
i >= m_cNodesandi >= m_cLinksmakes the check work correctly. However, both methods should return NULL if it's invalid.Conclusion
Note that it's just from a first look and a quick test. I don't know if there are cases or reasons that justify
i > m_cNodesandi > m_cLinks. Further tests may or may not be required but I won't have time to make an in depth testing for now, so I'll leave this PR as draft. Feel free to leave open, merge or close.