Commit e11d024
authored
[lgtm] Fix LGTM-reported issues. (#1074)
Remember CodeQL (5a0097b)? CodeQL basically runs [GitHub LGTM][0]
on source code, looking for possible security issues.
Now that CodeQL is running, we can begin addressing reported issues.
Problems found include:
* Result of call that may return NULL dereferenced unconditionally
* HttpClient created with CheckCertificateRevocationList disabled
* Arbitrary file write during archive extraction ("Zip Slip")
* Local-user-controlled data in path expression
~~ Result of call that may return NULL dereferenced unconditionally ~~
If **calloc**(3) returns `nullptr`, we shouldn't pass it on to
`MultiByteToWideChar()` or `WideCharToMultiByte()` without validation.
~~ HttpClient created with CheckCertificateRevocationList disabled ~~
Apparently the `HttpClient` default constructor is "bad"; we should
instead use the [`HttpClient(HttpMessageHandler)` constructor][1],
provide our own `HttpClientHandler`, and ensure that
[`HttpClientHandler.CheckCertificateRevocationList`][2] is True.
~~ Arbitrary file write during archive extraction ("Zip Slip") ~~
`tools/java-source-utils` (69e1b80) extracts the `.java` files
within `.jar`/`.aar`/.etc files to use for type resolution, as I
couldn't find an easier way to get `com.github.javaparser` to
use Java source code for type resolution purposes unless the Java
source code was on-disk. Unfortunately, the `.jar` extraction code
was susceptible to "Zip Slip", wherein an entry in the `.jar` may
overwrite unexpected files if it has an entry name of e.g.
`../../this/is/really/bad.java`. Fix this by verifying that the
target filename stays within the target directory structure, and
skip the entry when the name is invalid.
~~ Local-user-controlled data in path expression ~~
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"; consider
these `java-source-utils --help` fragments:
Java type resolution options:
--bootclasspath CLASSPATH
':'-separated list of .jar files to use
for type resolution.
-a, --aar FILE .aar file to use for type resolution.
-j, --jar FILE .jar file to use for type resolution.
-s, --source DIR Directory containing .java files for type
resolution purposes. DOES NOT parse all files.
These are all user-controlled, and they are necessary to allow
`java-source-utils` to *work*.
Similarly:
Output file options:
-P, --output-params FILE Write method parameter names to FILE.
-D, --output-javadoc FILE Write Javadoc within XML container to FILE.
LGTM complains that `--output-javadoc FILE` accepts a user-controlled
path which may control directory separator chars, and
*this is intentional*; using it would be annoying if that weren't true!
These uses can be ignored by appending the comment
`// lgtm [java/path-injection-local]`.
[0]: https://github.com/marketplace/lgtm
[1]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.-ctor?view=netstandard-2.0#system-net-http-httpclient-ctor(system-net-http-httpmessagehandler)
[2]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.checkcertificaterevocationlist?view=net-7.01 parent cf80deb commit e11d024
File tree
4 files changed
+37
-12
lines changed- build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks
- src/java-interop
- tools/java-source-utils/src/main/java/com/microsoft/android
4 files changed
+37
-12
lines changedLines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | | - | |
14 | | - | |
| 19 | + | |
15 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| |||
21 | 30 | | |
22 | 31 | | |
23 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
24 | 37 | | |
25 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
26 | 41 | | |
27 | | - | |
28 | | - | |
| 42 | + | |
29 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
30 | 48 | | |
31 | 49 | | |
32 | 50 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
322 | 326 | | |
323 | 327 | | |
324 | 328 | | |
| |||
343 | 347 | | |
344 | 348 | | |
345 | 349 | | |
346 | | - | |
| 350 | + | |
347 | 351 | | |
348 | 352 | | |
349 | 353 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
0 commit comments