INTERNAL: exception handling for wrong data messages 76/29776/2
authorgreatim <jaewon81.lim@samsung.com>
Tue, 4 Nov 2014 08:14:43 +0000 (17:14 +0900)
committergreatim <jaewon81.lim@samsung.com>
Tue, 4 Nov 2014 09:53:53 +0000 (18:53 +0900)
exception handling for wrong data messages

Change-Id: I98e88169f984e7bba21bdafd9cdcda4db89638a5
Signed-off-by: greatim <jaewon81.lim@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/DALimit.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/channel/data/DataChannelConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/MessageParser.java

index 3443969..9bd2df5 100644 (file)
@@ -379,6 +379,9 @@ public class AnalyzerConstants {
        public final static String REMOTE_DEVICE = "[Remote Device]";//$NON-NLS-1$
        public final static String LAUNCH_APP = "launch_app";//$NON-NLS-1$
        
+       public final static String CMDSCRIPT_UNKNOWN = "Unknown option";//$NON-NLS-1$
+       public final static String CMDSCRIPT_USAGE = "usage:";//$NON-NLS-1$
+       
        // file constants
        public final static int F_SETLKW = 7;
        
index 62a3469..37d51b4 100644 (file)
@@ -64,11 +64,12 @@ public class DALimit {
        // common
        public static final int MAX_TRACE_TIME_INSECOND = 24*60*60;     // 1 day
        public static final long MAX_SEQUENCE_NUMBER = Long.MAX_VALUE; //2^63-1,  4G*2G-1
-       public static final int MAX_PROCESS_COUNT = (int) Math.pow(2, 16);      // 65535
-       public static final int MAX_BINARY_COUNT = (int) Math.pow(2, 16); // 65535
+       public static final int MAX_PROCESS_COUNT = (int) Math.pow(2, 16);      // 65536
+       public static final int MAX_BINARY_COUNT = (int) Math.pow(2, 16); // 65536
        public static final int MAX_FUNCTION_COUNT = (int) Math.pow(2, 20);     // 1,048,576
        public static final int MAX_FUNCTION_ARGUMENTS_COUNT = FUNCTION_ARGUMENTS_FORMAT_LENGTH; // Because "MAX_FUNCTION_ARGUMENTS_COUNT < FUNCTION_ARGUMENTS_FORMAT_LENGTH" is always true
        public static final long MAX_DAEMON_LOG_SIZE = 1024*1024;       // 1 mega byte
+       public static final int MAX_PAYLOAD_SIZE = (int) Math.pow(2, 16); // 65536
        
        // Leak 
        public static final int MAX_LEAK_CHECK_BUFFER_SIZE = (int) Math.pow(2, 20); // 1,048,576
index 4895c8a..0d36c7f 100755 (executable)
@@ -28,13 +28,9 @@ package org.tizen.dynamicanalyzer.communicator;
 import static org.tizen.sdblib.util.DeviceUtil.isOnline;
 import static org.tizen.sdblib.util.IOUtil.tryClose;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -47,7 +43,6 @@ import org.tizen.dynamicanalyzer.common.path.PathConstants;
 import org.tizen.dynamicanalyzer.common.path.PathManager;
 import org.tizen.dynamicanalyzer.constant.CommonConstants;
 import org.tizen.dynamicanalyzer.model.DeviceInfo;
-import org.tizen.dynamicanalyzer.util.CommonUtil;
 import org.tizen.dynamicanalyzer.util.Logger;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.IShellOutputReceiver;
@@ -487,10 +482,15 @@ public class CommunicatorUtils {
                List<String> apiMap = new ArrayList<String>();
                apiMap.add("unknown");
 
-               for (int i = 0; i < lines.size(); i++) {
-                       String input = lines.get(i);
-                       String[] splitLine = input.trim().split(CommonConstants.SPACE, 2);
-                       apiMap.add(new String(splitLine[1]));
+               if (lines.size() > 0) {
+                       if (!lines.get(0).contains(AnalyzerConstants.CMDSCRIPT_UNKNOWN)
+                                       && !lines.get(0).contains(AnalyzerConstants.CMDSCRIPT_USAGE)) {
+                               for (int i = 0; i < lines.size(); i++) {
+                                       String input = lines.get(i);
+                                       String[] splitLine = input.trim().split(CommonConstants.SPACE, 2);
+                                       apiMap.add(new String(splitLine[1]));
+                               }
+                       }
                }
 
                return apiMap;
index 10561a8..f86c359 100644 (file)
@@ -47,9 +47,6 @@ public class DataChannelConstants {
        /* Custom Message Type */
        public final static int MSG_FUCNTION_ENTRY_EXIT = 0x0900;
 
-       public static final int LOG_USER_FUNCTION = 0x002C;  //44
-       public static final int LOG_CONTEXT_SWITCH = 0x002D;  //45 
-
        public final static int MSG_PROBE_MEMORY = 0x0101;
        public final static int MSG_PROBE_UICONTROL = 0x0102;
        public final static int MSG_PROBE_UIEVENT = 0x0103;
@@ -62,9 +59,4 @@ public class DataChannelConstants {
        public final static int MSG_PROBE_SYNC = 0x0110;
        public final static int MSG_PROBE_NETWORK = 0x0111;
        public final static int MSG_PROBE_GLES20 = 0x0112;
-       
-       public final static int DB_TYPE_PROFILE = 0x0001;
-       public final static int DB_TYPE_CONTEXTSWITCH = 0x0002;
-       public final static int DB_TYPE_PROBE = 0x0004;
-       public final static int DB_TYPE_SYSTEM = 0x0008;
 }
index 7201225..20f64ef 100755 (executable)
@@ -202,7 +202,7 @@ public class MessageParser {
                        pinfo.setDropLog(true);
                }
                pinfo.setMappingState(true);
-               
+
                ProcessMemoryMap pMap = new ProcessMemoryMap(pinfo.getPid(), subTime.getLongTime());
                pinfo.addProcessMemoryMap(pMap);
 
@@ -271,32 +271,33 @@ public class MessageParser {
 
                        BinaryInfo bininfo = project.getDeviceStatusInfo().getBinaryInfo(libPath);
                        LibraryObject libObj = new LibraryObject(bininfo.getID(), lowAddr, highAddr);
-                       if(!lastMap.addLibraryMap(libObj)) {
+                       if (!lastMap.addLibraryMap(libObj)) {
                                Logger.error("exist library");
                        }
-                       
+
                        pinfo.setMappingState(true);
                } else {
                        DATime changeTime = new DATime(sec, nano);
                        DATime profileStartTime = project.getProfilingStartTime();
                        DATime subTime = changeTime.subtract(profileStartTime);
-                       
-                       if(pinfo.isMapping()) {
+
+                       if (pinfo.isMapping()) {
                                // make new memory map
-                               ProcessMemoryMap newMap = new ProcessMemoryMap(pinfo.getPid(), subTime.getLongTime());
+                               ProcessMemoryMap newMap = new ProcessMemoryMap(pinfo.getPid(),
+                                               subTime.getLongTime());
                                pinfo.addProcessMemoryMap(newMap);
                                newMap.copy(lastMap);
-                               
+
                                // remove from new map
                                newMap.removeLibrary(lowAddr, highAddr);
                        } else {
                                // update captured time of last memory map
                                pinfo.updateProcessMemoryMap(lastMap, subTime.getLongTime());
-                               
+
                                // remove from map
                                lastMap.removeLibrary(lowAddr, highAddr);
                        }
-                       
+
                        pinfo.setMappingState(false);
                }
        }
@@ -358,11 +359,16 @@ public class MessageParser {
 
                                int id = ByteUtil.toInt(header, 0);
                                UnsignedInt seq = ByteUtil.toUnsignedInt(header, INT_SIZE);
-                               if(seq.equals(Long.valueOf(0))) {
+                               if (seq.equals(Long.valueOf(0))) {
                                        Global.getProject().incSeqRotation();
                                }
 
                                int payloadSize = ByteUtil.toInt(header, MSG_PAYLOAD_SIZE_INDEX);
+                               if (payloadSize < 0 || payloadSize > DALimit.MAX_PAYLOAD_SIZE) {
+                                       // wrong message format, stop profiling
+                                       break;
+                               }
+
                                byte[] payload = null;
 
                                try {
@@ -398,7 +404,11 @@ public class MessageParser {
                                        printWriter.printf("\n");
                                }
 
-                               processMessage(buffer);
+                               if (!processMessage(buffer)) {
+                                       // unknown message id
+                                       break;
+                               }
+
                                if (id == DataChannelConstants.MSG_DATA_TERMINATE) {
                                        Logger.debug("message data terminate arrived!!!");
                                        Logger.performance("TEST", "While tracing", "Terminate Application");
@@ -455,10 +465,10 @@ public class MessageParser {
                Logger.performance("TEST", "DA end", "Stop timer");
                addBufferToList();
                Logger.performance("TEST", "DA end", "Add buffer to list");
-               
+
                // stop DB insert thread
                DBInsertManager.stopInserters();
-               
+
                if (!StartProcessManager.getInstance().isCancelled()) {
                        Logger.debug("start!! : stop log process");//$NON-NLS-1$
                        StopLogProcessor.runStopLogProcessThread();
@@ -471,7 +481,9 @@ public class MessageParser {
                ReplayTraceHandler.startTime = null;
        }
 
-       private void processMessage(byte[] data) {
+       // return false if message id is unknown
+       private boolean processMessage(byte[] data) {
+               boolean bret = true;
                int id = ByteUtil.toInt(data, 0);
                LogData log = null;
                switch (id) {
@@ -496,7 +508,7 @@ public class MessageParser {
                        if ((runtime.totalMemory() - runtime.freeMemory()) >= runtime.maxMemory() * 0.95) {
                                DALimit.stopTraceAndOpenWarningDialog();
                        }
-                       
+
                        if (AnalyzerManager.isProcessInfoArrived()) {
                                // make log
                                log = LogDataFactory.createInstance(data);
@@ -536,14 +548,22 @@ public class MessageParser {
                        }
                }
                        break;
-               default: // MSG_PROBE
-                       if (AnalyzerManager.isProcessInfoArrived() && id > 0x0100 && id < 0x0200) {
-                               log = LogDataFactory.createInstance(data);
-                               if (null != log) {
-                                       buffer.add(log);
-                                       messageCount++;
+               case DataChannelConstants.MSG_DATA_IMAGE:
+                       break;
+               default:
+                       if (id > 0x0100 && id < 0x0200) { // MSG_PROBE
+                               if (AnalyzerManager.isProcessInfoArrived()) {
+                                       log = LogDataFactory.createInstance(data);
+                                       if (null != log) {
+                                               buffer.add(log);
+                                               messageCount++;
+                                       }
                                }
+                       } else {
+                               // unknown message id
+                               bret = false;
                        }
+
                        break;
                }
 
@@ -551,5 +571,7 @@ public class MessageParser {
                        addBufferToList();
                        messageCount = 0;
                }
+
+               return bret;
        }
 }