remove null bytes from strings before creating sql statements in backup

This commit is contained in:
Daniel Gultsch 2022-08-04 11:31:58 +02:00
parent 62a379862e
commit 67f021426b

View file

@ -15,6 +15,7 @@ import android.util.Log;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -114,7 +115,7 @@ public class ExportBackupService extends Service {
} }
builder.append(intValue); builder.append(intValue);
} else { } else {
DatabaseUtils.appendEscapedSQLString(builder, value); appendEscapedSQLString(builder, value);
} }
} }
builder.append(")"); builder.append(")");
@ -127,6 +128,10 @@ public class ExportBackupService extends Service {
writer.append(builder.toString()); writer.append(builder.toString());
} }
private static void appendEscapedSQLString(final StringBuilder sb, final String sqlString) {
DatabaseUtils.appendEscapedSQLString(sb, CharMatcher.is('\u0000').removeFrom(sqlString));
}
private static void simpleExport(SQLiteDatabase db, String table, String column, String uuid, PrintWriter writer) { private static void simpleExport(SQLiteDatabase db, String table, String column, String uuid, PrintWriter writer) {
final Cursor cursor = db.query(table, null, column + "=?", new String[]{uuid}, null, null, null); final Cursor cursor = db.query(table, null, column + "=?", new String[]{uuid}, null, null, null);
while (cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
@ -201,7 +206,7 @@ public class ExportBackupService extends Service {
} else if (value.matches("[0-9]+")) { } else if (value.matches("[0-9]+")) {
builder.append(value); builder.append(value);
} else { } else {
DatabaseUtils.appendEscapedSQLString(builder, value); appendEscapedSQLString(builder, value);
} }
} }
builder.append(")"); builder.append(")");