-
Notifications
You must be signed in to change notification settings - Fork 59
Prevent out of boundaries access in packmol.f90 #116
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
While reading input options.
|
Thanks for the contributions. Having a safeguard for that is nice, but we should throw an informative error instead, guiding to user to what to do (in this case, increase the maxkeywords parameter or revise the input file for errors, more likely). |
|
From what I understand, the input can actually be correct, since number of values could be maxkeywords. But doesn't invoke possible out of boundaries call. if ( keyword(iline,1) == "radius" ) then
read(keyword(iline,2),*,iostat=ioerr) value
if ( ioerr /= 0 ) then
write(*,*) ' ERROR: Could not read radius from keyword. '
stop exit_code_input_error
end if
ival = 2
do
if (ival > maxkeywords) exit ! <-- This is new line
read(keyword(iline_atoms,ival),*,iostat=ioerr) iat
if ( ioerr /= 0 ) exit ! This is original exit, which is not an input error I think
if ( iat > natoms(itype) ) then
write(*,*) ' ERROR: atom selection with index greater than number of '
write(*,*) ' atoms in structure ', itype
stop exit_code_input_error
end if
radius(icart+iat) = value
ival = ival + 1
end do
end if |
|
Oh, no, not really. These properties are not bound to The exit on reading error is used there to read until the end of line. |
|
Say I have:
When ival is 21, read value is where ival is 22, out of bounds happens ( |
|
Do you have an example of that happening? Because |
|
Attaching example: Here are the debug print: end if
ival = 2
do
+ IF ( ival > maxkeywords ) THEN
+ write(*,*), 'Here', ival, maxkeywords, iat, shape(keyword)
+ END IF
read(keyword(iline_atoms,ival),*,iostat=ioerr) iat
+ IF ( ival > maxkeywords ) THEN
+ write(*,*), 'Here1', ival, maxkeywords, iat, shape(keyword), ioerr
+ END IF
if ( ioerr /= 0 ) exit
if ( iat > natoms(itype) ) then
write(*,*) ' ERROR: atom selection with index greater than number of 'Output: |
|
Thanks, I had now time to look at it, and indeed, that was needed there. I changed in the main code your suggestion to the use of "do while", though. But thank you for pointing the issue. The fix is available in the 21.2.1 release. |
While reading input options.