[core] Don't trust SystemProperties (#970)

This commit is contained in:
vvb2060 2021-08-21 17:30:37 +08:00 committed by GitHub
parent c278d5f35b
commit dbc6df3cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -1,15 +1,15 @@
package org.lsposed.lspd.service;
import android.os.ParcelFileDescriptor;
import android.os.SystemProperties;
import android.util.Log;
import androidx.annotation.Nullable;
import org.lsposed.lspd.util.Utils;
import java.io.File;
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
public class LogcatService implements Runnable {
@ -22,8 +22,7 @@ public class LogcatService implements Runnable {
public LogcatService(File logPath) {
System.loadLibrary("daemon");
this.logPath = logPath;
var zone = ZoneId.of(SystemProperties.get("persist.sys.timezone", "GMT"));
logTimeFormat = DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(zone);
logTimeFormat = DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(Utils.getZoneId());
}
@Override

View File

@ -23,12 +23,10 @@ package org.lsposed.lspd.util;
import android.app.ActivityThread;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.SystemProperties;
import java.io.FileWriter;
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
@ -39,7 +37,7 @@ public class ModuleLogger {
public static void initLogger(ParcelFileDescriptor fileDescriptor) {
if (fd == null && fileDescriptor != null) {
fd = fileDescriptor;
var zone = ZoneId.of(SystemProperties.get("persist.sys.timezone", "GMT"));
var zone = Utils.getZoneId();
var pattern = "uuuu-MM-dd'T'HH:mm:ss.SSS"; // DateTimeFormatter.ISO_LOCAL_DATE_TIME
logDateFormat = DateTimeFormatter.ofPattern(pattern, Locale.ROOT).withZone(zone);
}

View File

@ -26,6 +26,10 @@ import android.util.Log;
import org.lsposed.lspd.BuildConfig;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.zone.ZoneRulesException;
public class Utils {
public static final String LOG_TAG = "LSPosed";
@ -64,4 +68,13 @@ public class Utils {
public static void logE(String msg, Throwable throwable) {
Log.e(LOG_TAG, msg, throwable);
}
public static ZoneId getZoneId() {
var timezone = SystemProperties.get("persist.sys.timezone", "GMT");
try {
return ZoneId.of(timezone);
} catch (ZoneRulesException e) {
return ZoneOffset.UTC;
}
}
}