Skip to content
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

Stop out-of-bounds read, and ensure all bytes are used, in FuncIntRandomMT #2716

Merged
merged 2 commits into from
Aug 22, 2018

Conversation

ChrisJefferson
Copy link
Contributor

This stops FuncIntRandomMT from reading off the end of a bag.

This isn't (currently) an actual problem, as it only reads up to a word-size, which is fine in GASMAN.

This appears to be (based on valgrind testing) the only place where we read a bag in word-sized chunks, where it's not reasonable to make sure the bag is word-sized at construction time.

@codecov
Copy link

codecov bot commented Aug 21, 2018

Codecov Report

Merging #2716 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2716      +/-   ##
==========================================
+ Coverage   75.75%   75.75%   +<.01%     
==========================================
  Files         478      478              
  Lines      241451   241459       +8     
==========================================
+ Hits       182902   182913      +11     
+ Misses      58549    58546       -3
Impacted Files Coverage Δ
src/intfuncs.c 93.61% <100%> (+0.16%) ⬆️
src/stats.c 89.62% <0%> (+0.19%) ⬆️
hpcgap/lib/hpc/stdtasks.g 63.93% <0%> (+0.51%) ⬆️

@ChrisJefferson ChrisJefferson added topic: kernel release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Aug 21, 2018
@ChrisJefferson
Copy link
Contributor Author

While adding tests (which I should have done in the first place), I found a small bug in this method -- it would round the length of the string down to the nearest multiple of 4, except when the string was of length less than 4.

I added a commit which fixes this. This will want to be mentioned in the release notes as it could change random numbers, but only because we are now using the whole string.

I could pull this into two PRs if anyone prefers that.

@ChrisJefferson ChrisJefferson changed the title Stop out-of-bounds read in FuncIntRandomMT Stop out-of-bounds read, and ensure all bytes are used, in FuncIntRandomMT Aug 21, 2018
Copy link
Member

@markuspf markuspf left a comment

Choose a reason for hiding this comment

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

Can this change "random" numbers? If so that should be noted in the release notes.

@ChrisJefferson
Copy link
Contributor Author

The original part of this PR (don't read off the end of bags) wouldn't change random numbers. The second commit (I realised we aren't actually using all the string given) will change random numbers, when generated from a string which satisfies len(s)>4 and len(s)%4 != 0. I don't know how many such strings have existed in the past, but they certainly could :)

@fingolfin
Copy link
Member

I think most such strings would have been obtained by querying the current state of the RNG, and thus its len would have been a multiple of 4. So I think this is fine, but it really should be documented explicitly in the release notes.

@fingolfin fingolfin merged commit 31cabd7 into gap-system:master Aug 22, 2018
@ChrisJefferson ChrisJefferson deleted the funcintrandom branch August 24, 2018 15:51
@fingolfin
Copy link
Member

@ChrisJefferson could you please add it to the 4.10 release notes then (in the wiki)?

@ChrisJefferson ChrisJefferson added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Sep 21, 2018
@ChrisJefferson
Copy link
Contributor Author

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: added PRs introducing changes that have since been mentioned in the release notes topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants