Skip to content

Commit f6c0972

Browse files
committed
JS: Guard other uses of Gson.fromJson
1 parent fc12b0b commit f6c0972

File tree

1 file changed

+9
-1
lines changed
  • javascript/extractor/src/com/semmle/js/dependencies

1 file changed

+9
-1
lines changed

javascript/extractor/src/com/semmle/js/dependencies/Fetcher.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.regex.Pattern;
2020

2121
import com.google.gson.Gson;
22+
import com.google.gson.JsonParseException;
23+
2224
import com.semmle.js.dependencies.packument.Packument;
2325

2426
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -84,7 +86,13 @@ public Packument getPackument(String packageName) throws IOException {
8486
}
8587
System.out.println("Fetching package metadata for " + packageName);
8688
try (Reader reader = new BufferedReader(new InputStreamReader(fetch("https://registry.npmjs.org/" + packageName)))) {
87-
return new Gson().fromJson(reader, Packument.class);
89+
Packument packument = new Gson().fromJson(reader, Packument.class);
90+
if (packument == null) {
91+
throw new IOException("Malformed packument for " + packageName);
92+
}
93+
return packument;
94+
} catch (JsonParseException ex) {
95+
throw new IOException("Malformed packument for " + packageName, ex);
8896
}
8997
}
9098

0 commit comments

Comments
 (0)