mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-20 15:04:23 +00:00
json parsing exception handling, see Coverity issues 72297, 72296, 72295
This commit is contained in:
+5
@@ -35,6 +35,7 @@ import org.cryptomator.crypto.engine.UnsupportedVaultFormatException;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
||||||
|
|
||||||
class CryptorImpl implements Cryptor {
|
class CryptorImpl implements Cryptor {
|
||||||
|
|
||||||
@@ -99,9 +100,13 @@ class CryptorImpl implements Cryptor {
|
|||||||
try {
|
try {
|
||||||
final ObjectMapper om = new ObjectMapper();
|
final ObjectMapper om = new ObjectMapper();
|
||||||
keyFile = om.readValue(masterkeyFileContents, KeyFile.class);
|
keyFile = om.readValue(masterkeyFileContents, KeyFile.class);
|
||||||
|
if (keyFile == null) {
|
||||||
|
throw new InvalidFormatException("Could not read masterkey file", keyFile, KeyFile.class);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalArgumentException("Unable to parse masterkeyFileContents", e);
|
throw new IllegalArgumentException("Unable to parse masterkeyFileContents", e);
|
||||||
}
|
}
|
||||||
|
assert keyFile != null;
|
||||||
|
|
||||||
// check version
|
// check version
|
||||||
if (keyFile.getVersion() != CURRENT_VAULT_VERSION || ArrayUtils.isEmpty(keyFile.getVersionMac())) {
|
if (keyFile.getVersion() != CURRENT_VAULT_VERSION || ArrayUtils.isEmpty(keyFile.getVersionMac())) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -70,6 +71,9 @@ public class VaultObjectMapperProvider implements Provider<ObjectMapper> {
|
|||||||
@Override
|
@Override
|
||||||
public Vault deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
public Vault deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||||
final JsonNode node = jp.readValueAsTree();
|
final JsonNode node = jp.readValueAsTree();
|
||||||
|
if (node == null || !node.has("path")) {
|
||||||
|
throw new InvalidFormatException("Node is null or doesn't contain a path.", node, Vault.class);
|
||||||
|
}
|
||||||
final String pathStr = node.get("path").asText();
|
final String pathStr = node.get("path").asText();
|
||||||
final Path path = FileSystems.getDefault().getPath(pathStr);
|
final Path path = FileSystems.getDefault().getPath(pathStr);
|
||||||
final Vault vault = vaultFactoy.createVault(path);
|
final Vault vault = vaultFactoy.createVault(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user