Skip to content

Commit 3a762ed

Browse files
committed
Prevent command line pollution from allowing privilege escalation
See matching commit in su-binary repo
1 parent 4d45429 commit 3a762ed

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/com/noshufou/android/su/provider/PermissionsProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private boolean ensureDb() {
456456

457457
private class SuDbOpenHelper extends SQLiteOpenHelper {
458458
private static final String DATABASE_NAME = "su.db";
459-
private static final int DATABASE_VERSION = 5;
459+
private static final int DATABASE_VERSION = 6;
460460

461461
SuDbOpenHelper(Context context) {
462462
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -513,7 +513,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
513513
upgradeVersion = 4;
514514
}
515515

516-
if (upgradeVersion == 4) {
516+
if (upgradeVersion <= 5) {
517517
Cursor c = db.query(Apps.TABLE_NAME, null, null, null, null, null, null);
518518
while (c.moveToNext()) {
519519
Util.writeStoreFile(mContext,
@@ -524,7 +524,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
524524
}
525525
c.close();
526526
mContext.deleteDatabase("permissions.sqlite");
527-
upgradeVersion = 5;
527+
upgradeVersion = 6;
528528
}
529529

530530
}

src/com/noshufou/android/su/util/Util.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,18 @@ public static boolean writeStoreFile(Context context, int uid, int execUid, Stri
795795
try {
796796
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(
797797
new File(storedDir.getAbsolutePath() + File.separator + fileName)));
798+
switch (allow) {
799+
case AllowType.ALLOW:
800+
out.write("allow\n");
801+
break;
802+
case AllowType.DENY:
803+
out.write("deny\n");
804+
break;
805+
default:
806+
out.write("prompt\n");
807+
}
798808
out.write(cmd);
799809
out.write('\n');
800-
out.write(String.valueOf(allow));
801-
out.write('\n');
802810
out.flush();
803811
out.close();
804812
} catch (FileNotFoundException e) {
@@ -819,14 +827,8 @@ public static boolean writeDefaultStoreFile(Context context) {
819827
String action = prefs.getString(Preferences.AUTOMATIC_ACTION, "prompt");
820828
try {
821829
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(defFile.getAbsolutePath()));
822-
out.write("default\n");
823-
if (action.equals("allow")) {
824-
out.write("1");
825-
} else if (action.equals("deny")) {
826-
out.write("0");
827-
} else {
828-
out.write("-1");
829-
}
830+
out.write(action);
831+
out.write("\n");
830832
out.flush();
831833
out.close();
832834
} catch (FileNotFoundException e) {

0 commit comments

Comments
 (0)