Skip to content

Commit 5fa7ac4

Browse files
authored
[java-source-utils] Fix lgtm java/path-injection-local (#1079)
Context: e11d024 Commit e11d024 attempted to fix LGTM-reported [`java/path-injection-local`][0] warnings by using the comment `// lgtm [java/path-injection-local]`. Unfortunately, this is insufficient: the comment *also* needs to provide a 25+ character justification for why the offending statement can be ignored. This justification was not provided. Update the `// lgtm [java/path-injection-local]` comments to provide a justification, as required by tooling. Copying the longer justification from e11d024: > LGTM is complaining that `tools/java-source-utils` (69e1b80) accepts > user-controlled data. These warnings will be *ignored* because the > app is *unusable* without "user-controlled data" > … > These are all user-controlled, and they are necessary to allow > `java-source-utils` to *work*. > … > LGTM complains that `--output-javadoc FILE` accepts a user-controlled > path which may [contain] directory separator chars, and > *this is intentional*; using it would be annoying if that weren't true! See also [`JavaSourceUtils.cs`][1], which passes [a value][2] located within `$(IntermediateOutputPath)` to `java-source-utils.jar --output-javadoc`. Allowing `--output-javadoc` to contain directory separator chars is what makes this possible! [0]: https://github.com/github/codeql/blob/f192191e8c4c14d70a86342de47c8882516c7c25/java/ql/src/Security/CWE/CWE-022/TaintedPath.qhelp [1]: https://github.com/xamarin/xamarin-android/blob/b00185c485287c2c5f0350a067ebc178aec2382c/src/Xamarin.Android.Build.Tasks/Tasks/JavaSourceUtils.cs#L134-L135 [2]: https://github.com/xamarin/xamarin-android/blob/b00185c485287c2c5f0350a067ebc178aec2382c/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.ClassParse.targets#L69
1 parent 120d8a7 commit 5fa7ac4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

tools/java-source-utils/src/main/java/com/microsoft/android/JavaSourceUtilsOptions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private final JavaSourceUtilsOptions parse(Iterator<String> args) throws IOExcep
167167
final String bootClassPath = getNextOptionValue(args, arg);
168168
final ArrayList<File> files = new ArrayList<File>();
169169
for (final String cp : bootClassPath.split(File.pathSeparator)) {
170-
final File file = new File(cp); // lgtm [java/path-injection-local]
170+
final File file = new File(cp); // lgtm [java/path-injection-local] java-source-utils.jar is a command-line app, and is useless if it doesn't support command-line args.
171171
if (!file.exists()) {
172172
System.err.println(App.APP_NAME + ": warning: invalid file path for option `-bootclasspath`: " + cp);
173173
continue;
@@ -253,7 +253,7 @@ private final JavaSourceUtilsOptions parse(Iterator<String> args) throws IOExcep
253253
if (arg.startsWith("@")) {
254254
// response file?
255255
final String responseFileName = arg.substring(1);
256-
final File responseFile = new File(responseFileName); // lgtm [java/path-injection-local]
256+
final File responseFile = new File(responseFileName); // lgtm [java/path-injection-local] java-source-utils.jar is a command-line app, and is useless if it doesn't support command-line args.
257257
if (responseFile.exists()) {
258258
final Iterator<String> lines =
259259
Files.readAllLines(responseFile.toPath())
@@ -267,7 +267,7 @@ private final JavaSourceUtilsOptions parse(Iterator<String> args) throws IOExcep
267267
break;
268268
}
269269
}
270-
final File file = new File(arg); // lgtm [java/path-injection-local]
270+
final File file = new File(arg); // lgtm [java/path-injection-local] java-source-utils.jar is a command-line app, and is useless if it doesn't support command-line args.
271271
if (!file.exists()) {
272272
System.err.println(App.APP_NAME + ": warning: invalid file path for option `FILES`: " + arg);
273273
break;
@@ -347,7 +347,7 @@ static File getNextOptionFile(final Iterator<String> args, final String option)
347347
throw new IllegalArgumentException(
348348
"Expected required value for option `" + option + "`.");
349349
final String fileName = args.next();
350-
final File file = new File(fileName); // lgtm [java/path-injection-local]
350+
final File file = new File(fileName); // lgtm [java/path-injection-local] java-source-utils.jar is a command-line app, and is useless if it doesn't support command-line args.
351351
if (!file.exists()) {
352352
System.err.println(App.APP_NAME + ": warning: invalid file path for option `" + option + "`: " + fileName);
353353
return null;

tools/java-source-utils/src/main/java/com/microsoft/android/JavadocXmlGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public JavadocXmlGenerator(final String output) throws FileNotFoundException, Pa
3939
if (output == null)
4040
this.output = System.out;
4141
else {
42-
final File file = new File(output); // lgtm [java/path-injection-local]
42+
final File file = new File(output); // lgtm [java/path-injection-local] java-source-utils.jar is a command-line app, and is useless if it doesn't support command-line args.
4343
final File parent = file.getParentFile();
4444
if (parent != null) {
4545
parent.mkdirs();

0 commit comments

Comments
 (0)