Skip to content

Commit e16376e

Browse files
committed
Add an extra line to the default store file to prevent a vulnerability
1 parent 7a4d491 commit e16376e

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

src/com/noshufou/android/su/HomeActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ protected void onCreate(Bundle savedInstanceState) {
9595
ChangeLog cl = new ChangeLog(this);
9696
if (cl.firstRun()) {
9797
cl.getLogDialog().show();
98+
Util.writeDetaultStoreFile(this);
9899
}
99100

100101
// Check for root enabled on CyanogenMod 9

src/com/noshufou/android/su/preferences/PreferencesActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
284284
mToastLocation.setEnabled(sharedPreferences
285285
.getString(Preferences.NOTIFICATION_TYPE, "toast").equals("toast"));
286286
} else if (key.equals(Preferences.AUTOMATIC_ACTION)) {
287-
Util.writeDetaultStoreFile(this, sharedPreferences.getString(key, "prompt"));
287+
Util.writeDetaultStoreFile(this);
288288
}
289289
}
290290

src/com/noshufou/android/su/preferences/PreferencesFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
246246
} else if (key.equals(Preferences.PIN)) {
247247
setDepsNfc(sharedPreferences.getBoolean(Preferences.PIN, false));
248248
} else if (key.equals(Preferences.AUTOMATIC_ACTION)) {
249-
Util.writeDetaultStoreFile(getActivity(), sharedPreferences.getString(key, "prompt"));
249+
Util.writeDetaultStoreFile(getActivity());
250250
}
251251
}
252252

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.noshufou.android.su.preferences.Preferences;
5858
import com.noshufou.android.su.preferences.PreferencesActivity;
5959
import com.noshufou.android.su.preferences.PreferencesActivityHC;
60+
import com.noshufou.android.su.provider.PermissionsProvider.Apps.AllowType;
6061
import com.noshufou.android.su.service.UpdaterService;
6162

6263
public class Util {
@@ -810,28 +811,31 @@ public static boolean writeStoreFile(Context context, int uid, int execUid, Stri
810811
return true;
811812
}
812813

813-
public static boolean writeDetaultStoreFile(Context context, String action) {
814-
File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored");
815-
storedDir.mkdirs();
816-
File defFile = new File(storedDir.getAbsolutePath() + File.separator + "default");
817-
try {
818-
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(defFile.getAbsolutePath()));
819-
if (action.equals("allow")) {
820-
out.write("1");
821-
} else if (action.equals("deny")) {
822-
out.write("0");
823-
} else {
824-
out.write("-1");
825-
}
826-
out.flush();
827-
out.close();
828-
} catch (FileNotFoundException e) {
829-
Log.w(TAG, "Default file not written", e);
830-
return false;
831-
} catch (IOException e) {
832-
Log.w(TAG, "Default file not written", e);
833-
return false;
834-
}
835-
return true;
814+
public static boolean writeDetaultStoreFile(Context context) {
815+
File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored");
816+
storedDir.mkdirs();
817+
File defFile = new File(storedDir.getAbsolutePath() + File.separator + "default");
818+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
819+
String action = prefs.getString(Preferences.AUTOMATIC_ACTION, "prompt");
820+
try {
821+
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.flush();
831+
out.close();
832+
} catch (FileNotFoundException e) {
833+
Log.w(TAG, "Default file not written", e);
834+
return false;
835+
} catch (IOException e) {
836+
Log.w(TAG, "Default file not written", e);
837+
return false;
838+
}
839+
return true;
836840
}
837841
}

0 commit comments

Comments
 (0)