Skip to content

Add check on cache length when purging entries #68

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

Closed
wants to merge 1 commit into from

Conversation

athum
Copy link

@athum athum commented Jun 15, 2020

When the authenticator's cache is purged, there was a consistent slice bounds out of range [:200] with capacity 181 panic occurring. Checking that the count variable here does not exceed the actual length of the cache should avoid this panic when the cache is purged.

limit := count
if len(cache) < count {
limit = len(cache) - 1
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the issue correctly, when Purge is called with count >= len(cache), this triggers a panic because of the range. I think an easier fix would be to just empty the entire cache in this case, right after grabbing a lock, because this is what I think this code effectively does. Or am I missing something?

Also, can you please add a test for this edge case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abbot sorry for the delayed response - you are correct! I think the current count parameter is to only clear the cache up to a certain point - is this something that can be removed in favor of clearing the entire cache?

@athum
Copy link
Author

athum commented Aug 28, 2020

Moved to #70.

@athum athum closed this Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants