Frank Kobzik has uploaded a new change for review.

Change subject: engine:  VM Linux Boot options aren't parsing properly
......................................................................

engine:  VM Linux Boot options aren't parsing properly

Steps to Reproduce:
1. have VM & init & kernel file on ISO domain
2. use Boot params =>  kernel/initrd params
3. put to initrd: "iso://rhel6.initrd " (without quotes, with space at the end)

After starting the VM it runs for a moment and then it crashes with VDSM error:
libvirtError('virDomainCreateXML() failed', conn=self).
Fixed by adding validation of the user input (on frontend) and setting of
VmBase parameters (on backend).

Change-Id: I9ccb4fc0b807c77bc17cfe02903341cdf4e51d54
Signed-off-by: Frantisek Kobzik <fkob...@redhat.com>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=872178
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
9 files changed, 78 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/50/9550/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
index fe61cfe..cf29da5 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java
@@ -29,7 +29,7 @@
 public class VmBase extends IVdcQueryable implements INotifyPropertyChanged, 
BusinessEntity<Guid> {
     private static final long serialVersionUID = 1078548170257965614L;
     private ArrayList<DiskImage> images;
-    private ArrayList<DiskImage> diskList = new ArrayList<DiskImage>();
+    private final ArrayList<DiskImage> diskList = new ArrayList<DiskImage>();
     private List<VmNetworkInterface> interfaces;
     private Map<Guid, VmDevice> vmManagedDeviceMap = new HashMap<Guid, 
VmDevice>();
     private List<VmDevice> vmUnManagedDeviceList = new ArrayList<VmDevice>();
@@ -122,14 +122,23 @@
 
     @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE)
     @Column(name = "kernel_url", length = 
BusinessEntitiesDefinitions.GENERAL_MAX_SIZE)
+    @Pattern(regexp = ValidationUtils.NO_TRIMMING_WHITE_SPACES_PATTERN,
+            message = 
"ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES", 
groups = { CreateEntity.class,
+                    UpdateEntity.class })
     private String kernelUrl;
 
     @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE)
     @Column(name = "kernel_params", length = 
BusinessEntitiesDefinitions.GENERAL_MAX_SIZE)
+    @Pattern(regexp = ValidationUtils.NO_TRIMMING_WHITE_SPACES_PATTERN,
+            message = 
"ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES", 
groups = { CreateEntity.class,
+                    UpdateEntity.class })
     private String kernelParams;
 
     @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE)
     @Column(name = "initrd_url", length = 
BusinessEntitiesDefinitions.GENERAL_MAX_SIZE)
+    @Pattern(regexp = ValidationUtils.NO_TRIMMING_WHITE_SPACES_PATTERN,
+            message = 
"ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES", 
groups = { CreateEntity.class,
+                    UpdateEntity.class })
     private String initrdUrl;
 
     @Column(name = "allow_console_reconnect")
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
index 79215c7..e3a5eb9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
@@ -25,6 +25,7 @@
     public static final String DOMAIN_NAME_PATTERN =
             
"^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}$";
     public static final String NO_WHITES_SPACE_PATTERN = "\\S+";
+    public static final String NO_TRIMMING_WHITE_SPACES_PATTERN = 
"^$|\\S.*\\S";
     public static final String IP_PATTERN =
             
"^\\b((25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\.){3}(25[0-5]|2[0-4]\\d|[01]\\d\\d|\\d?\\d)\\b$|^$";
     // NULLABLE_MAC_ADDRESS can be valid mac address: xx:xx:xx:xx:xx:xx or 
empty string,
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index d5a516f..5a315b5 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -165,6 +165,7 @@
     ACTION_TYPE_FAILED_NAME_LENGTH_IS_TOO_LONG,
     ACTION_TYPE_FAILED_NAME_MAY_NOT_BE_EMPTY,
     ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS,
+    ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES,
     ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS_OR_DASH,
     ACTION_TYPE_FAILED_INVALID_VDS_HOSTNAME,
     ACTION_TYPE_FAILED_HOSNAME_CANNOT_CHANGE,
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 7d0bf96..6013bdd 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -612,6 +612,7 @@
 ACTION_TYPE_FAILED_HOSNAME_CANNOT_CHANGE=Host Address can not be modified due 
to Security restrictions.  In order to change Host Address, Host has to be 
reinstalled
 CAN_DO_ACTION_DATABASE_CONNECTION_FAILURE=Action failed due to database 
connection failure. Please check connectivity to your Database server.
 ACTION_TYPE_FAILED_DESCRIPTION_MAY_NOT_CONTAIN_SPECIAL_CHARS=Cannot ${action} 
${type}. The given description contains special characters.\nOnly alpha-numeric 
and some special characters that conform to the standard ASCII character set 
are allowed.
+ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES=Cannot
 ${action} ${type}. Linux boot parameters contain trimming whitespace 
characters.
 ACTION_TYPE_FAILED_NAME_LENGTH_IS_TOO_LONG=Cannot ${action} ${type}. The given 
name is too long.
 ACTION_TYPE_FAILED_NAME_MAY_NOT_BE_EMPTY=Can not ${action} ${type}. The given 
name is empty.
 ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS=Can not ${action} 
${type}. The given name contains special characters. Only lower-case and 
upper-case letters, numbers, '_', '-', '.' are allowed.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 9c25876..99b1cc4 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -1636,6 +1636,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. The given description 
contains special characters.\nOnly alpha-numeric and some special characters 
that conform to the standard ASCII character set are allowed.")
     String ACTION_TYPE_FAILED_DESCRIPTION_MAY_NOT_CONTAIN_SPECIAL_CHARS();
 
+    @DefaultStringValue("Cannot ${action} ${type}. Linux boot parameters 
contain trimming whitespace characters.")
+    String 
ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES();
+
     @DefaultStringValue("Cannot ${action} ${type}. The given name is too 
long.")
     String ACTION_TYPE_FAILED_NAME_LENGTH_IS_TOO_LONG();
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
index b694ae0..b0b8ac3 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
@@ -19,6 +19,7 @@
 import org.ovirt.engine.core.common.businessentities.storage_domains;
 import org.ovirt.engine.core.common.businessentities.storage_pool;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.common.utils.ValidationUtils;
 import org.ovirt.engine.core.compat.Event;
 import org.ovirt.engine.core.compat.EventArgs;
 import org.ovirt.engine.core.compat.Guid;
@@ -1927,39 +1928,62 @@
             getInitrd_path().setEntity(""); //$NON-NLS-1$
         }
 
-        if (isLinux_Unassign_UnknownOS
-                && ((((String) getKernel_parameters().getEntity()).length() > 
0 || ((String) getInitrd_path().getEntity()).length() > 0) && ((String) 
getKernel_path().getEntity()).length() == 0))
+        if (isLinux_Unassign_UnknownOS)
         {
-            boolean kernelParamInvalid = false;
-            boolean inetdPathInvalid = false;
-            if (((String) getKernel_parameters().getEntity()).length() > 0)
-            {
+            String kernelPath = (String) getKernel_path().getEntity();
+            String initrdPath = (String) getInitrd_path().getEntity();
+            String kernelParams = (String) getKernel_parameters().getEntity();
+
+            String cannotStartOrEndWithWhitespaceMsg = 
ConstantsManager.getInstance()
+                    .getConstants().trimmingSpacesInField();
+            if (hasTrimmingWhitespaces(kernelPath)) {
+                getKernel_path().setIsValid(false);
+                
getInitrd_path().getInvalidityReasons().add(cannotStartOrEndWithWhitespaceMsg);
+            }
+            if (hasTrimmingWhitespaces(kernelParams)) {
                 getKernel_parameters().setIsValid(false);
-                kernelParamInvalid = true;
+                
getKernel_parameters().getInvalidityReasons().add(cannotStartOrEndWithWhitespaceMsg);
             }
-            if (((String) getInitrd_path().getEntity()).length() > 0)
-            {
+            if (hasTrimmingWhitespaces(initrdPath)) {
                 getInitrd_path().setIsValid(false);
-                inetdPathInvalid = true;
+                
getInitrd_path().getInvalidityReasons().add(cannotStartOrEndWithWhitespaceMsg);
             }
 
-            String msg =
-                    ConstantsManager.getInstance()
-                            .getMessages()
-                            .invalidPath(kernelParamInvalid ? 
ConstantsManager.getInstance()
-                                    .getConstants()
-                                    .kernelInvalid() : "", //$NON-NLS-1$
-                                    kernelParamInvalid && inetdPathInvalid ? 
ConstantsManager.getInstance()
-                                            .getConstants()
-                                            .or() : "", //$NON-NLS-1$
-                                    inetdPathInvalid ? 
ConstantsManager.getInstance()
-                                            .getConstants()
-                                            .inetdInvalid() : ""); 
//$NON-NLS-1$
+            if ((kernelParams.length() > 0 || initrdPath.length() > 0) && 
kernelPath.length() == 0)
+            {
+                boolean kernelParamInvalid = false;
+                boolean inetdPathInvalid = false;
 
-            getKernel_path().setIsValid(false);
-            getInitrd_path().getInvalidityReasons().add(msg);
-            getKernel_parameters().getInvalidityReasons().add(msg);
-            getKernel_path().getInvalidityReasons().add(msg);
+                if (kernelParams.length() > 0)
+                {
+                    getKernel_parameters().setIsValid(false);
+                    kernelParamInvalid = true;
+                }
+                if (initrdPath.length() > 0)
+                {
+                    getInitrd_path().setIsValid(false);
+                    inetdPathInvalid = true;
+                }
+
+                String msg =
+                        ConstantsManager.getInstance()
+                                .getMessages()
+                                .invalidPath(kernelParamInvalid ? 
ConstantsManager.getInstance()
+                                        .getConstants()
+                                        .kernelInvalid() : "", //$NON-NLS-1$
+                                        kernelParamInvalid && inetdPathInvalid 
? ConstantsManager.getInstance()
+                                                .getConstants()
+                                                .or() : "", //$NON-NLS-1$
+                                        inetdPathInvalid ? 
ConstantsManager.getInstance()
+                                                .getConstants()
+                                                .inetdInvalid() : ""); 
//$NON-NLS-1$
+
+                getKernel_path().setIsValid(false);
+                getInitrd_path().getInvalidityReasons().add(msg);
+                getKernel_parameters().getInvalidityReasons().add(msg);
+                getKernel_path().getInvalidityReasons().add(msg);
+            }
+
         }
 
         boolean customPropertySheetValid = getCustomPropertySheet().validate();
@@ -1986,8 +2010,13 @@
                 && getDefaultHost().getIsValid() && getMemSize().getIsValid() 
&& getMinAllocatedMemory().getIsValid()
                 && getNumOfMonitors().getIsValid() && getDomain().getIsValid() 
&& getUsbPolicy().getIsValid()
                 && getTimeZone().getIsValid() && getOSType().getIsValid() && 
getCdImage().getIsValid()
-                && getKernel_path().getIsValid() && behavior.Validate()
-                && customPropertySheetValid;
+                && getKernel_path().getIsValid() && 
getKernel_parameters().getIsValid() && getInitrd_path().getIsValid()
+                && behavior.Validate() && customPropertySheetValid;
+    }
+
+    private boolean hasTrimmingWhitespaces(String string) {
+        String noTrimmingSpacesPattern = "^$|\\S.*\\S";
+        return !string.matches(noTrimmingSpacesPattern);
     }
 
     class TotalCpuCoresComposableValidation implements IValidation {
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
index 8d22841..7fec8c7 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
@@ -922,6 +922,9 @@
     @DefaultStringValue("This field can't be empty.")
     String thisFieldCantBeEmptyInvalidReason();
 
+    @DefaultStringValue("This field can't contain trimming whitespace 
characters.")
+    String trimmingSpacesInField();
+
     @DefaultStringValue("Quota enforcement activated. Quota must be defined 
for the selected storage domain")
     String quotaMustBeSelectedInvalidReason();
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 7743fb0..7a1cb85 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -605,6 +605,7 @@
 ACTION_TYPE_FAILED_HOSNAME_CANNOT_CHANGE=Host Address can not be modified due 
to Security restrictions.  In order to change Host Address, Host has to be 
reinstalled
 CAN_DO_ACTION_DATABASE_CONNECTION_FAILURE=Action failed due to database 
connection failure. Please check connectivity to your Database server.
 ACTION_TYPE_FAILED_DESCRIPTION_MAY_NOT_CONTAIN_SPECIAL_CHARS=Cannot ${action} 
${type}. The given description contains special characters.\nOnly alpha-numeric 
and some special characters that conform to the standard ASCII character set 
are allowed.
+ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES=Cannot
 ${action} ${type}. Linux boot parameters contain trimming whitespace 
characters.
 ACTION_TYPE_FAILED_NAME_LENGTH_IS_TOO_LONG=Cannot ${action} ${type}. The given 
name is too long.
 ACTION_TYPE_FAILED_NAME_MAY_NOT_BE_EMPTY=Can not ${action} ${type}. The given 
name is empty.
 ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS=Can not ${action} 
${type}. The given name contains special characters. Only lower-case and 
upper-case letters, numbers, '_', '-', '.' are allowed.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 6076ef1..725fbb8 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -604,6 +604,7 @@
 ACTION_TYPE_FAILED_HOSNAME_CANNOT_CHANGE=Host Address can not be modified due 
to Security restrictions.  In order to change Host Address, Host has to be 
reinstalled
 CAN_DO_ACTION_DATABASE_CONNECTION_FAILURE=Action failed due to database 
connection failure. Please check connectivity to your Database server.
 ACTION_TYPE_FAILED_DESCRIPTION_MAY_NOT_CONTAIN_SPECIAL_CHARS=Cannot ${action} 
${type}. The given description contains special characters.\nOnly alpha-numeric 
and some special characters that conform to the standard ASCII character set 
are allowed.
+ACTION_TYPE_FAILED_LINUX_BOOT_PARAMS_MAY_NOT_CONTAIN_TRIMMING_WHITESPACES=Cannot
 ${action} ${type}. Linux boot parameters contain trimming whitespace 
characters.
 ACTION_TYPE_FAILED_NAME_LENGTH_IS_TOO_LONG=Cannot ${action} ${type}. The given 
name is too long.
 ACTION_TYPE_FAILED_NAME_MAY_NOT_BE_EMPTY=Can not ${action} ${type}. The given 
name is empty.
 ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS=Can not ${action} 
${type}. The given name contains special characters. Only lower-case and 
upper-case letters, numbers, '_', '-', '.' are allowed.


--
To view, visit http://gerrit.ovirt.org/9550
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9ccb4fc0b807c77bc17cfe02903341cdf4e51d54
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Frank Kobzik <fkob...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to