You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2019/01/15 11:23:42 UTC
[jena] branch master updated: Fix: Protect against use with memory
locations and "file not found".
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/master by this push:
new f77d743 Fix: Protect against use with memory locations and "file not found".
f77d743 is described below
commit f77d743efe6efe3bf9cc2e3b8e68751597531323
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Tue Jan 15 11:23:30 2019 +0000
Fix: Protect against use with memory locations and "file not found".
---
.../apache/jena/tdb2/setup/StoreParamsCodec.java | 34 +++++++++++++++-------
.../apache/jena/tdb/setup/StoreParamsCodec.java | 34 +++++++++++++++-------
2 files changed, 46 insertions(+), 22 deletions(-)
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/StoreParamsCodec.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/StoreParamsCodec.java
index ccc4ccc..e6d8f35 100644
--- a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/StoreParamsCodec.java
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/setup/StoreParamsCodec.java
@@ -20,10 +20,7 @@ package org.apache.jena.tdb2.setup;
import static org.apache.jena.tdb2.setup.StoreParamsConst.*;
-import java.io.BufferedOutputStream ;
-import java.io.FileOutputStream ;
-import java.io.IOException ;
-import java.io.OutputStream ;
+import java.io.*;
import org.apache.jena.atlas.io.IO ;
import org.apache.jena.atlas.json.* ;
@@ -53,23 +50,38 @@ public class StoreParamsCodec {
catch (IOException ex) { IO.exception(ex); }
}
- /** Read from a file */
+ /**
+ * Read from a file if possible.
+ * Return null for memory locations, file not found or syntax errors.
+ */
public static StoreParams read(Location location) {
+ if ( location.isMem() )
+ return null ;
return read(location.getPath(Names.TDB_CONFIG_FILE)) ;
}
-
- /** Read from a file, if possible. */
+
+ /**
+ * Read from a file if possible.
+ * Return null if the file is not found or has a syntax error.
+ */
public static StoreParams read(String filename) {
try {
- JsonObject obj = JSON.read(filename) ;
+ InputStream in = IO.openFileEx(filename);
+ if ( in == null )
+ return null;
+ JsonObject obj = JSON.parse(in) ;
return StoreParamsCodec.decode(obj) ;
- }
- catch (JsonParseException ex) {
+ } catch (FileNotFoundException ex) {
+ return null;
+ } catch (JsonParseException ex) {
FmtLog.warn(StoreParamsCodec.class, "Ignoring store params : Syntax error in '%s': [line:%d, col:%d] %s", filename, ex.getLine(), ex.getColumn(), ex.getMessage());
return null ;
+ } catch (IOException e) {
+ IO.exception(e);
+ return null;
}
}
-
+
public static JsonObject encodeToJson(StoreParams params) {
JsonBuilder builder = new JsonBuilder() ;
builder.startObject("StoreParams") ; // "StoreParams" is an internal alignment marker - not in the JSON.
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/setup/StoreParamsCodec.java b/jena-tdb/src/main/java/org/apache/jena/tdb/setup/StoreParamsCodec.java
index 511f6bd..f192a8d 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/setup/StoreParamsCodec.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/setup/StoreParamsCodec.java
@@ -20,10 +20,7 @@ package org.apache.jena.tdb.setup;
import static org.apache.jena.tdb.setup.StoreParamsConst.*;
-import java.io.BufferedOutputStream ;
-import java.io.FileOutputStream ;
-import java.io.IOException ;
-import java.io.OutputStream ;
+import java.io.*;
import org.apache.jena.atlas.io.IO ;
import org.apache.jena.atlas.json.*;
@@ -52,23 +49,38 @@ public class StoreParamsCodec {
catch (IOException ex) { IO.exception(ex); }
}
- /** Read from a file */
+ /**
+ * Read from a file if possible.
+ * Return null for memory locations, file not found or syntax errors.
+ */
public static StoreParams read(Location location) {
+ if ( location.isMem() )
+ return null ;
return read(location.getPath(TDB_CONFIG_FILE)) ;
}
-
- /** Read from a file, if possible. */
+
+ /**
+ * Read from a file if possible.
+ * Return null if the file is not found or has a syntax error.
+ */
public static StoreParams read(String filename) {
try {
- JsonObject obj = JSON.read(filename) ;
+ InputStream in = IO.openFileEx(filename);
+ if ( in == null )
+ return null;
+ JsonObject obj = JSON.parse(in) ;
return StoreParamsCodec.decode(obj) ;
- }
- catch (JsonParseException ex) {
+ } catch (FileNotFoundException ex) {
+ return null;
+ } catch (JsonParseException ex) {
FmtLog.warn(StoreParamsCodec.class, "Ignoring store params : Syntax error in '%s': [line:%d, col:%d] %s", filename, ex.getLine(), ex.getColumn(), ex.getMessage());
return null ;
+ } catch (IOException e) {
+ IO.exception(e);
+ return null;
}
}
-
+
public static JsonObject encodeToJson(StoreParams params) {
JsonBuilder builder = new JsonBuilder() ;
builder.startObject("StoreParams") ; // "StoreParams" is an internal alignment marker - not in the JSON.