Skip to content

Commit

Permalink
Introduced protections against predictable RNG abuse
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot[bot] authored Sep 3, 2024
1 parent 5a4b5fa commit 97d8c5d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.gradle.internal.util.ports;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -28,7 +29,7 @@ public class ReservedPortRange {
public ReservedPortRange(int startPort, int endPort) {
this.startPort = startPort;
this.endPort = endPort;
current = startPort + new Random().nextInt(endPort - startPort);
current = startPort + new SecureRandom().nextInt(endPort - startPort);
}

public List<Integer> getAllocated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.elasticsearch.tdigest;

import java.security.SecureRandom;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -29,7 +30,7 @@
import static org.elasticsearch.tdigest.IntAVLTree.NIL;

public class AVLTreeDigest extends AbstractTDigest {
final Random gen = new Random();
final Random gen = new SecureRandom();
private final double compression;
private AVLGroupTree summary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

package org.elasticsearch.tdigest;

import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;

/**
* Static sorting methods
*/
public class Sort {
private static final Random prng = new Random(); // for choosing pivots during quicksort
private static final Random prng = new SecureRandom(); // for choosing pivots during quicksort

/**
* Single-key stabilized quick sort on using an index array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;

import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.security.SecureRandom;

import org.elasticsearch.core.PathUtils;
import org.elasticsearch.core.SuppressForbidden;
Expand Down Expand Up @@ -51,7 +52,7 @@ private static class TestRecord {

@SuppressForbidden(reason = "It is ok to use Random outside of an actual test")
private static Random rnd() {
return new Random();
return new SecureRandom();
}

public static void main(String[] args) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;

import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.security.SecureRandom;

import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.PathUtils;
Expand Down Expand Up @@ -241,7 +242,7 @@ private String unitTestExporterScript() {

@SuppressForbidden(reason = "It is ok to use Random outside of an actual test")
private static Random rnd() {
return new Random();
return new SecureRandom();
}

public static void main(String[] args) throws Exception {
Expand Down

0 comments on commit 97d8c5d

Please sign in to comment.