Changed: Allow connections from root o sockets.

This commit is contained in:
tareksander
2021-12-08 10:29:13 +01:00
committed by agnostic-apollo
parent 33b88b5d4b
commit 3dee2eb486
3 changed files with 15 additions and 11 deletions

View File

@@ -209,16 +209,20 @@ public class LocalFilesystemSocket
if (backlog <= 0) {
throw new IllegalArgumentException("Backlog has to be at least 1");
}
if (path == null) {
throw new IllegalArgumentException("path cannot be null");
if (path == null || path.length() == 0) {
throw new IllegalArgumentException("path cannot be null or empty");
}
this.path = path;
File f = new File(path);
File parent = f.getParentFile();
if (parent != null) {
parent.mkdirs();
if (path.getBytes(StandardCharsets.UTF_8)[0] != 0) {
// not a socket in the abstract linux namespace, make sure the path is accessible and clear
File f = new File(path);
File parent = f.getParentFile();
if (parent != null) {
parent.mkdirs();
}
f.delete();
}
f.delete();
fd = createserversocket(path.getBytes(StandardCharsets.UTF_8), backlog);
if (fd == -1) {
throw new IOException("Could not create UNIX server socket at \""+path+"\"");
@@ -245,9 +249,9 @@ public class LocalFilesystemSocket
c = -1;
continue;
}
if (peeruid == app.getApplicationInfo().uid) {
// if the peer has the same uid, allow the connection
// if the peer has the same uid or is root, allow the connection
if (peeruid == app.getApplicationInfo().uid || peeruid == 0) {
break;
} else {
Logger.logWarn("LocalFilesystemSocket.ServerSocket", "WARNING: An app with the uid of "+peeruid+" tried to connect to the socket at \""+path+"\", closing connection.");

View File

@@ -77,7 +77,6 @@ public class LocalSocketListener
while ((c = r.read()) > 0) {
b.append((char) c);
}
Logger.logDebug(LOG_TAG, b.toString());
String outString;
String errString;
int ret;