pokt-network / pocket

Official implementation of the Pocket Network Protocol v1
https://pokt.network
MIT License
61 stars 33 forks source link

[IBC] Add length check in RemovePrefix function #876

Closed innocent-saeed36 closed 12 months ago

innocent-saeed36 commented 12 months ago

Problem:

The RemovePrefix function in prefix.go currently performs a slice operation on the path argument without first checking if the path is long enough to accommodate the slice operation. If the length of path is less than the combined length of prefix and delimiter, this will result in a runtime panic due to out-of-range slice indices.

Solution:

This PR adds a check to ensure the length of path is sufficient before the slice operation is performed. If the length of path is less than the combined length of prefix and delimiter, the function returns an empty string.

Changes:

Added length check to RemovePrefix function in prefix.go.

Olshansk commented 12 months ago

I do not believe this is a necessary check