Skip to content

Commit ecd7004

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
bug 11978: don't allow passing -, + and spaces for instance.name config param
status 11978: resolved fixed
1 parent 102f460 commit ecd7004

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public enum Config {
144144

145145
AccountCleanupInterval("Advanced", ManagementServer.class, Integer.class, "account.cleanup.interval", "86400", "The interval (in seconds) between cleanup for removed accounts", null),
146146
AllowPublicUserTemplates("Advanced", ManagementServer.class, Integer.class, "allow.public.user.templates", "true", "If false, users will not be able to create public templates.", null),
147-
InstanceName("Advanced", AgentManager.class, String.class, "instance.name", "VM", "Name of the deployment instance.", null),
147+
InstanceName("Advanced", AgentManager.class, String.class, "instance.name", "VM", "Name of the deployment instance.", "instanceName"),
148148
ExpungeDelay("Advanced", UserVmManager.class, Integer.class, "expunge.delay", "86400", "Determines how long (in seconds) to wait before actually expunging destroyed vm. The default value = the default value of expunge.interval", null),
149149
ExpungeInterval("Advanced", UserVmManager.class, Integer.class, "expunge.interval", "86400", "The interval (in seconds) to wait before running the expunge thread.", null),
150150
ExpungeWorkers("Advanced", UserVmManager.class, Integer.class, "expunge.workers", "1", "Number of workers performing expunge ", null),

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,11 @@ private String validateConfigurationValue(String name, String value) {
520520
return "Please enter valid hypervisor type";
521521
}
522522
}
523-
} else {
523+
} else if (range.equalsIgnoreCase("instanceName")) {
524+
if (!NetUtils.verifyInstanceName(value)) {
525+
return "Instance name can not contain hyphen, spaces and \"+\" char";
526+
}
527+
}else {
524528
String[] options = range.split(",");
525529
for (String option : options) {
526530
if (option.trim().equalsIgnoreCase(value)) {

‎utils/src/com/cloud/utils/net/NetUtils.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,5 +1060,15 @@ public static boolean validateGuestCidr(String cidr) {
10601060
return false;
10611061
}
10621062
}
1063+
1064+
public static boolean verifyInstanceName(String instanceName) {
1065+
//instance name for cloudstack vms shouldn't contain - and spaces
1066+
if (instanceName.contains("-") || instanceName.contains(" ") || instanceName.contains("+")) {
1067+
s_logger.warn("Instance name can not contain hyphen, spaces and \"+\" char");
1068+
return false;
1069+
}
1070+
1071+
return true;
1072+
}
10631073

10641074
}

0 commit comments

Comments
 (0)