Do not close zip input stream
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
bb43804d58
commit
5aa8191cd3
@ -43,8 +43,10 @@ import com.wireguard.android.widget.fab.FloatingActionsMenuRecyclerViewScrollLis
|
|||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
import com.wireguard.config.ParseException;
|
import com.wireguard.config.ParseException;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -122,7 +124,8 @@ public class TunnelListFragment extends BaseFragment {
|
|||||||
throw new IllegalArgumentException("File must be .conf or .zip");
|
throw new IllegalArgumentException("File must be .conf or .zip");
|
||||||
|
|
||||||
if (isZip) {
|
if (isZip) {
|
||||||
try (ZipInputStream zip = new ZipInputStream(contentResolver.openInputStream(uri))) {
|
try (ZipInputStream zip = new ZipInputStream(contentResolver.openInputStream(uri));
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(zip))) {
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
while ((entry = zip.getNextEntry()) != null) {
|
while ((entry = zip.getNextEntry()) != null) {
|
||||||
if (entry.isDirectory())
|
if (entry.isDirectory())
|
||||||
@ -140,7 +143,7 @@ public class TunnelListFragment extends BaseFragment {
|
|||||||
continue;
|
continue;
|
||||||
Config config = null;
|
Config config = null;
|
||||||
try {
|
try {
|
||||||
config = Config.parse(zip);
|
config = Config.parse(reader);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throwables.add(e);
|
throwables.add(e);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,18 @@ public final class Config {
|
|||||||
* @return a {@code Config} instance representing the supplied configuration
|
* @return a {@code Config} instance representing the supplied configuration
|
||||||
*/
|
*/
|
||||||
public static Config parse(final InputStream stream) throws IOException, ParseException {
|
public static Config parse(final InputStream stream) throws IOException, ParseException {
|
||||||
|
return parse(new BufferedReader(new InputStreamReader(stream)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an series of "Interface" and "Peer" sections into a {@code Config}. Throws
|
||||||
|
* {@link ParseException} if the input is not well-formed or contains unparseable sections.
|
||||||
|
*
|
||||||
|
* @param reader a BufferedReader of UTF-8 text that is interpreted as a WireGuard configuration file
|
||||||
|
* @return a {@code Config} instance representing the supplied configuration
|
||||||
|
*/
|
||||||
|
public static Config parse(final BufferedReader reader) throws IOException, ParseException {
|
||||||
final Builder builder = new Builder();
|
final Builder builder = new Builder();
|
||||||
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
|
||||||
final Collection<String> interfaceLines = new ArrayList<>();
|
final Collection<String> interfaceLines = new ArrayList<>();
|
||||||
final Collection<String> peerLines = new ArrayList<>();
|
final Collection<String> peerLines = new ArrayList<>();
|
||||||
boolean inInterfaceSection = false;
|
boolean inInterfaceSection = false;
|
||||||
@ -86,7 +96,6 @@ public final class Config {
|
|||||||
throw new ParseException("top level", "", "Empty configuration");
|
throw new ParseException("top level", "", "Empty configuration");
|
||||||
// Combine all [Interface] sections in the file.
|
// Combine all [Interface] sections in the file.
|
||||||
builder.parseInterface(interfaceLines);
|
builder.parseInterface(interfaceLines);
|
||||||
}
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user