changeset 218:2c4078b58289

8133654: DIO OPEN permissions must be checked before others: GPIO, I2C, SPI, UART Summary: Permission check was moved to the beginning of open functions Reviewed-by: snazarki Contributed-by: alexey.savin@oracle.com
author snazarki
date Fri, 14 Aug 2015 16:05:22 +0300
parents 5ba9c2a51405
children 4d7a1b32cc39
files src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java src/share/classes/com/oracle/dio/i2cbus/impl/I2CSlaveImpl.java src/share/classes/com/oracle/dio/spibus/impl/SPISlaveImpl.java src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java
diffstat 4 files changed, 16 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java	Thu Aug 13 21:02:44 2015 +0300
+++ b/src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java	Fri Aug 14 16:05:22 2015 +0300
@@ -53,6 +53,9 @@
     DeviceNotFoundException, InvalidDeviceConfigException{
         super(dscr, mode);
 
+        GPIOPinPermission permission = new GPIOPinPermission(getSecurityName());
+        AccessController.checkPermission(permission);
+
         GPIOPinConfig cfg = dscr.getConfiguration();
 
         if(cfg.getControllerName() != null) {
@@ -61,9 +64,6 @@
             );
         }
 
-        GPIOPinPermission permission = new GPIOPinPermission(getSecurityName());
-        AccessController.checkPermission(permission);
-
         openPinByConfig0( cfg.getControllerNumber(), cfg.getPinNumber(),
                           cfg.getDirection(), cfg.getDriveMode(),
                           cfg.getTrigger(), cfg.getInitValue(),
--- a/src/share/classes/com/oracle/dio/i2cbus/impl/I2CSlaveImpl.java	Thu Aug 13 21:02:44 2015 +0300
+++ b/src/share/classes/com/oracle/dio/i2cbus/impl/I2CSlaveImpl.java	Fri Aug 14 16:05:22 2015 +0300
@@ -51,6 +51,9 @@
             DeviceNotFoundException, InvalidDeviceConfigException {
         super(dscr, mode);
 
+        I2CPermission permission = new I2CPermission(getSecurityName());
+        AccessController.checkPermission(permission);
+
         I2CDeviceConfig cfg = dscr.getConfiguration();
 
         if (cfg.getControllerName() != null) {
@@ -59,9 +62,6 @@
             );
         }
 
-        I2CPermission permission = new I2CPermission(getSecurityName());
-        AccessController.checkPermission(permission);
-
         open0(cfg, mode == DeviceManager.EXCLUSIVE);
 
         initPowerManagement();
--- a/src/share/classes/com/oracle/dio/spibus/impl/SPISlaveImpl.java	Thu Aug 13 21:02:44 2015 +0300
+++ b/src/share/classes/com/oracle/dio/spibus/impl/SPISlaveImpl.java	Fri Aug 14 16:05:22 2015 +0300
@@ -70,6 +70,9 @@
             IOException, DeviceNotFoundException, InvalidDeviceConfigException {
         super(dscr, mode);
 
+        SPIPermission permission = new SPIPermission(getSecurityName());
+        AccessController.checkPermission(permission);
+
         SPIDeviceConfig cfg = dscr.getConfiguration();
         if(cfg.getControllerName() != null) {
             throw new InvalidDeviceConfigException(
@@ -77,9 +80,6 @@
             );
         }
 
-        SPIPermission permission = new SPIPermission(getSecurityName());
-        AccessController.checkPermission(permission);
-
         openSPIDeviceByConfig0(cfg.getControllerNumber(), cfg.getAddress(),
                                         cfg.getCSActiveLevel(), cfg.getClockFrequency(),
                                         cfg.getClockMode(), cfg.getWordLength(),
--- a/src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java	Thu Aug 13 21:02:44 2015 +0300
+++ b/src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java	Fri Aug 14 16:05:22 2015 +0300
@@ -84,17 +84,9 @@
                                 throws DeviceNotFoundException, InvalidDeviceConfigException, UnsupportedAccessModeException{
         super(dscr, mode);
 
-        String deviceName;
         byte[] devName; // UTF-8 device name
-
-        if( mode != DeviceManager.EXCLUSIVE){
-            throw new UnsupportedAccessModeException();
-        }
-
-        UARTConfig cfg = dscr.getConfiguration();
-
         //deviceName = uart device prefix + device number
-        deviceName = getSecurityName();
+        String deviceName = getSecurityName();
 
         if (deviceName == null){
             throw new DeviceNotFoundException(
@@ -105,6 +97,12 @@
         UARTPermission permission = new UARTPermission(deviceName);
         AccessController.checkPermission(permission);
 
+        if( mode != DeviceManager.EXCLUSIVE){
+            throw new UnsupportedAccessModeException();
+        }
+
+        UARTConfig cfg = dscr.getConfiguration();
+
         try{
             devName = deviceName.getBytes("UTF-8");
         } catch (UnsupportedEncodingException ex) {