Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Introduced protections against DoS via unterminated read operations
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot committed Aug 22, 2023
1 parent fde7f29 commit 58ca99a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/github/gilday/darkmode/DarkModeDetector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.gilday.darkmode;

import io.github.pixee.security.BoundedLineReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -22,9 +23,9 @@ static boolean isMacOsDarkMode() {
new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stderrReader =
new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
final String stdout = stdoutReader.readLine();
stderrReader.readLine(); // skip first line of output
final String stderr = stderrReader.readLine();
final String stdout = BoundedLineReader.readLine(stdoutReader, 1000000);
BoundedLineReader.readLine(stderrReader, 1000000); // skip first line of output
final String stderr = BoundedLineReader.readLine(stderrReader, 1000000);
if ("Dark".equals(stdout)) {
return true;
}
Expand Down Expand Up @@ -55,9 +56,9 @@ static Boolean isWindowsDarkMode() {

try (BufferedReader stdoutReader =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {
stdoutReader.readLine();
stdoutReader.readLine();
final String stdout = stdoutReader.readLine();
BoundedLineReader.readLine(stdoutReader, 1000000);
BoundedLineReader.readLine(stdoutReader, 1000000);
final String stdout = BoundedLineReader.readLine(stdoutReader, 1000000);
if (stdout.endsWith("0")) {
return true;
} else if (stdout.endsWith("1")) {
Expand Down

0 comments on commit 58ca99a

Please sign in to comment.