nagaboinaramgopal opened a new pull request, #14140:
URL: https://github.com/apache/cloudstack/pull/14140

   ### Description
   
   updateResourceLimit only accepts -1 (unlimited) for a root admin account, 
but the check compared `max.shortValue() != Resource.RESOURCE_UNLIMITED`. `max` 
is a Long, so `shortValue()` keeps only the low 16 bits, and any limit whose 
low 16 bits are all ones (65535, 131071, ...) truncates to -1. Such a value 
gets past the "Only -1 limit is supported for Root Admin accounts" check and is 
stored on the root admin account, while an ordinary value like 100 is rejected 
as expected. This compares the full value instead.
   
   The same code is on 4.20, 4.22 and main, so this targets 4.20.
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] build/CI
   - [ ] test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [ ] Minor
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [x] Minor
   - [ ] Trivial
   
   ### Screenshots (if appropriate):
   
   N/A
   
   ### How Has This Been Tested?
   
   Added 
`updateResourceLimitRejectsAFiniteLimitForRootAdminEvenWhenItsLowBitsLookUnlimited`
 to `ResourceLimitManagerImplTest`. It calls updateResourceLimit for a root 
admin account with 65535 and expects the "Only -1 limit" rejection. It fails 
against the current code (the update goes through) and passes with the fix, and 
the rest of `ResourceLimitManagerImplTest` (56 tests) passes.
   
       mvn -pl server test -Dtest=ResourceLimitManagerImplTest
   
   Also verified on a live 4.23 KVM environment with the same one line change, 
calling updateResourceLimit through the API for the root admin account `admin` 
(resourcetype 0, user VMs).
   
   Before the change, 65535 is accepted and stored on the root admin account, 
while 100 is rejected:
   
       22:07:06 
command=updateResourceLimit&account=admin&resourcetype=0&max=65535  HTTP/1.1 
200  "max":65535
       22:07:06 
command=updateResourceLimit&account=admin&resourcetype=0&max=100    HTTP/1.1 
431  Only -1 limit is supported for Root Admin accounts
       22:07:06 command=updateResourceLimit&account=admin&resourcetype=0&max=-1 
    HTTP/1.1 200
   
   With the change, 65535 is rejected like any other finite value, and -1 is 
still accepted:
   
       22:08:04 
command=updateResourceLimit&account=admin&resourcetype=0&max=65535  HTTP/1.1 
431  Only -1 limit is supported for Root Admin accounts
       22:08:04 
command=updateResourceLimit&account=admin&resourcetype=0&max=100    HTTP/1.1 
431  Only -1 limit is supported for Root Admin accounts
       22:08:04 command=updateResourceLimit&account=admin&resourcetype=0&max=-1 
    HTTP/1.1 200
   
   #### How did you try to break this feature and the system with this change?
   
   -1 is still accepted for root admin accounts, values that were already 
rejected stay rejected, and limits for accounts that are not root admins are 
not affected since this check only runs for root admins.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to