Fix: Verify number of bytes contained in sessiond agent commands
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / LttngTcpSessiondClient.java
index 6177feac7a849cefb44e959197e30894b295f529..37f4ec4e59289c0f146d1766573af02e97254492 100644 (file)
@@ -21,6 +21,7 @@ package org.lttng.ust.agent.client;
 import java.io.BufferedReader;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
@@ -179,7 +180,16 @@ public class LttngTcpSessiondClient implements Runnable {
        }
 
        private static String getHomePath() {
-               return System.getProperty("user.home");
+               /*
+                * The environment variable LTTNG_HOME overrides HOME if
+                * defined.
+                */
+               String homePath = System.getenv("LTTNG_HOME");
+
+               if (homePath == null) {
+                       homePath = System.getProperty("user.home");
+               }
+               return homePath;
        }
 
        /**
@@ -190,9 +200,10 @@ public class LttngTcpSessiondClient implements Runnable {
        private static int getPortFromFile(String path) throws IOException {
                int port;
                BufferedReader br = null;
+               File file = new File(path);
 
                try {
-                       br = new BufferedReader(new FileReader(path));
+                       br = new BufferedReader(new FileReader(file));
                        String line = br.readLine();
                        port = Integer.parseInt(line, 10);
                        if (port < 0 || port > 65535) {
@@ -363,7 +374,10 @@ public class LttngTcpSessiondClient implements Runnable {
                        return null;
                }
 
-               this.inFromSessiond.read(payload, 0, payload.length);
+               int read = inFromSessiond.read(payload, 0, payload.length);
+               if (read != payload.length) {
+                       throw new IOException("Unexpected number of bytes read in sessiond command payload");
+               }
                return payload;
        }
 
This page took 0.027684 seconds and 5 git commands to generate.