Skip to content

Commit b45d63f

Browse files
Likitha ShettyPrachi Damle
authored andcommitted
CLOUDSTACK-1131
[EC2 Query API] RunInstances allows negative values for paramters 'MinCount' and 'MaxCount' Add parameter validation to ensure MinCount is greater than 0 and MaxCount is great than or equal to MinCount
1 parent e5bb55c commit b45d63f

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

‎awsapi/src/com/cloud/bridge/service/EC2RestServlet.java‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,14 +1142,26 @@ private void runInstances( HttpServletRequest request, HttpServletResponse respo
11421142
else { response.sendError(530, "Missing ImageId parameter" ); return; }
11431143

11441144
String[] minCount = request.getParameterValues( "MinCount" );
1145-
if ( null != minCount && 0 < minCount.length )
1146-
EC2request.setMinCount( Integer.parseInt( minCount[0] ));
1147-
else { response.sendError(530, "Missing MinCount parameter" ); return; }
1145+
if ( minCount == null || minCount.length < 1) {
1146+
response.sendError(530, "Missing MinCount parameter" );
1147+
return;
1148+
} else if ( Integer.parseInt(minCount[0]) < 1) {
1149+
throw new EC2ServiceException(ClientError.InvalidParameterValue,
1150+
"Value of parameter MinCount should be greater than 0");
1151+
} else {
1152+
EC2request.setMinCount( Integer.parseInt( minCount[0]) );
1153+
}
11481154

11491155
String[] maxCount = request.getParameterValues( "MaxCount" );
1150-
if ( null != maxCount && 0 < maxCount.length )
1151-
EC2request.setMaxCount( Integer.parseInt( maxCount[0] ));
1152-
else { response.sendError(530, "Missing MaxCount parameter" ); return; }
1156+
if ( maxCount == null || maxCount.length < 1) {
1157+
response.sendError(530, "Missing MaxCount parameter" );
1158+
return;
1159+
} else if ( Integer.parseInt(maxCount[0]) < 1) {
1160+
throw new EC2ServiceException(ClientError.InvalidParameterValue,
1161+
"Value of parameter MaxCount should be greater than 0");
1162+
} else {
1163+
EC2request.setMaxCount( Integer.parseInt( maxCount[0]) );
1164+
}
11531165

11541166
String[] instanceType = request.getParameterValues( "InstanceType" );
11551167
if ( null != instanceType && 0 < instanceType.length )

‎awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,17 @@ public RunInstancesResponse runInstances(RunInstances runInstances) {
731731
EC2RunInstances request = new EC2RunInstances();
732732

733733
request.setTemplateId(rit.getImageId());
734-
request.setMinCount(rit.getMinCount());
735-
request.setMaxCount(rit.getMaxCount());
734+
735+
if (rit.getMinCount() < 1) {
736+
throw new EC2ServiceException(ClientError.InvalidParameterValue,
737+
"Value of parameter MinCount should be greater than 0");
738+
} else request.setMinCount( rit.getMinCount() );
739+
740+
if (rit.getMaxCount() < 1) {
741+
throw new EC2ServiceException(ClientError.InvalidParameterValue,
742+
"Value of parameter MaxCount should be greater than 0");
743+
} else request.setMaxCount(rit.getMaxCount());
744+
736745
if (null != type) request.setInstanceType(type);
737746
if (null != prt) request.setZoneName(prt.getAvailabilityZone());
738747
if (null != userData) request.setUserData(userData.getData());

0 commit comments

Comments
 (0)