Skip to content

Commit 2210888

Browse files
committed
2 parents 5004277 + 7b74c43 commit 2210888

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

app/src/main/java/com/atakmap/android/meshtastic/MeshtasticDropDownReceiver.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.atakmap.android.meshtastic.plugin.R;
3131
import com.atakmap.android.meshtastic.util.Constants;
3232
import com.atakmap.coremap.log.Log;
33+
import com.atakmap.coremap.filesystem.FileSystemUtils;
3334
import com.geeksville.mesh.ATAKProtos;
3435
import com.geeksville.mesh.AppOnlyProtos;
3536
import com.geeksville.mesh.ConfigProtos;
@@ -53,7 +54,6 @@
5354
import java.io.IOException;
5455
import java.io.InputStream;
5556
import java.io.InputStreamReader;
56-
import java.io.OutputStream;
5757
import java.nio.ByteBuffer;
5858
import java.nio.ByteOrder;
5959
import java.util.ArrayList;
@@ -548,15 +548,22 @@ public void initModel() throws IOException {
548548
deleteContents(targetDir);
549549
copyAssets(assetManager, sourcePath, targetDir);
550550
// Copy uuid
551-
copyFile(assetManager, sourcePath + "/uuid", targetDir);
551+
FileSystemUtils.copyFromAssetsToStorageFile(
552+
pluginContext,
553+
sourcePath + "/uuid",
554+
"tools/s2c/" + targetPath + "/" + sourcePath + "/uuid",
555+
true
556+
);
552557

553558
this.model = new Model(resultPath);
554559
Log.d(TAG, "Model ready");
555560

556561
}
557562

558563
private static String readLine(InputStream is) throws IOException {
559-
return new BufferedReader(new InputStreamReader(is)).readLine();
564+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
565+
return reader.readLine();
566+
}
560567
}
561568

562569
private static boolean deleteContents(File dir) {
@@ -596,19 +603,6 @@ private static void copyAssets(AssetManager assetManager, String path, File outP
596603
}
597604
}
598605

599-
private static void copyFile(AssetManager assetManager, String fileName, File outPath) throws IOException {
600-
InputStream in;
601-
in = assetManager.open(fileName);
602-
OutputStream out = new FileOutputStream(outPath + "/" + fileName);
603-
604-
byte[] buffer = new byte[4000];
605-
int read;
606-
while ((read = in.read(buffer)) != -1) {
607-
out.write(buffer, 0, read);
608-
}
609-
in.close();
610-
out.close();
611-
}
612606

613607
public void recognizeMicrophone() {
614608
Log.d(TAG, "recognizeMicrophone");

app/src/main/java/com/atakmap/android/meshtastic/MeshtasticMapComponent.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252

5353
import javax.xml.parsers.SAXParser;
5454
import javax.xml.parsers.SAXParserFactory;
55+
import javax.xml.XMLConstants;
56+
import com.atakmap.coremap.xml.XMLUtils;
5557

5658
public class MeshtasticMapComponent extends DropDownMapComponent
5759
implements CommsMapComponent.PreSendProcessor,
@@ -403,6 +405,15 @@ private void handleGenericCotEvent(CotEvent cotEvent, int hopLimit, int channel)
403405
exiResult.setOutputStream(osEXI);
404406

405407
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
408+
try {
409+
saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
410+
saxParserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
411+
saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
412+
saxParserFactory.setFeature("http://xml.org/sax/features/validation", false);
413+
saxParserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
414+
} catch (Exception e) {
415+
Log.w(TAG, "Failed to configure secure SAXParserFactory", e);
416+
}
406417
SAXParser newSAXParser = saxParserFactory.newSAXParser();
407418
XMLReader xmlReader = newSAXParser.getXMLReader();
408419
xmlReader.setContentHandler(exiResult.getHandler());

app/src/main/java/com/atakmap/android/meshtastic/MeshtasticReceiver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import javax.xml.transform.TransformerFactory;
9595
import javax.xml.transform.sax.SAXSource;
9696
import javax.xml.transform.stream.StreamResult;
97+
import com.atakmap.coremap.xml.XMLUtils;
9798

9899
public class MeshtasticReceiver extends BroadcastReceiver implements CotServiceRemote.CotEventListener {
99100
// constants
@@ -948,7 +949,7 @@ protected void receive(Intent intent) {
948949
InputSource is = new InputSource(new ByteArrayInputStream(combined));
949950
SAXSource exiSource = new EXISource(exiFactory);
950951
exiSource.setInputSource(is);
951-
TransformerFactory tf = TransformerFactory.newInstance();
952+
TransformerFactory tf = XMLUtils.getTransformerFactory();
952953
Transformer transformer = tf.newTransformer();
953954
transformer.transform(exiSource, result);
954955
CotEvent cotEvent = CotEvent.parse(writer.toString());
@@ -973,7 +974,7 @@ protected void receive(Intent intent) {
973974
InputSource is = new InputSource(new ByteArrayInputStream(payload.getBytes()));
974975
SAXSource exiSource = new EXISource(exiFactory);
975976
exiSource.setInputSource(is);
976-
TransformerFactory tf = TransformerFactory.newInstance();
977+
TransformerFactory tf = XMLUtils.getTransformerFactory();
977978
Transformer transformer = tf.newTransformer();
978979
transformer.transform(exiSource, result);
979980
CotEvent cotEvent = CotEvent.parse(writer.toString());

0 commit comments

Comments
 (0)