From 3967e863f5123365f8070993c32950ba4725935a Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sat, 28 Jul 2018 00:34:55 +0200 Subject: [PATCH] Fix sending wrongly encoded commands into the unix subshell (fixes #1198) --- .../com/nutomic/syncthingandroid/util/Util.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java index 096e499d..35c2e75e 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java @@ -15,9 +15,11 @@ import android.widget.Toast; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.service.Constants; +import java.io.BufferedWriter; import java.io.DataOutputStream; -import java.io.IOException; import java.io.File; +import java.io.IOException; +import java.io.OutputStreamWriter; import java.text.DecimalFormat; import eu.chainfire.libsuperuser.Shell; @@ -139,13 +141,6 @@ public class Util { useRoot = true; } - // Check for cyrillic characters in the folder path. - if (absoluteFolderPath.matches(".*\\p{InCyrillic}.*")) { - Log.w(TAG, "nativeBinaryCanWriteToPath: Path '" + absoluteFolderPath + - "' contains cyrillic characters. As this is currently not handled, we'll return true without checking permissions."); - return true; - } - // Write permission test file. String touchFile = absoluteFolderPath + "/" + TOUCH_FILE_NAME; int exitCode = runShellCommand("echo \"\" > \"" + touchFile + "\"\n", useRoot); @@ -185,9 +180,10 @@ public class Util { try { shellProc = Runtime.getRuntime().exec((useRoot) ? "su" : "sh"); shellOut = new DataOutputStream(shellProc.getOutputStream()); + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(shellOut)); Log.d(TAG, "runShellCommand: " + cmd); - shellOut.writeBytes(cmd); - shellOut.flush(); + bufferedWriter.write(cmd); + bufferedWriter.flush(); shellOut.close(); shellOut = null; exitCode = shellProc.waitFor();