summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regress/lib/libc/qsort/qsort_test.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/regress/lib/libc/qsort/qsort_test.c b/src/regress/lib/libc/qsort/qsort_test.c
index f78137504a..b23f3e6190 100644
--- a/src/regress/lib/libc/qsort/qsort_test.c
+++ b/src/regress/lib/libc/qsort/qsort_test.c
@@ -24,6 +24,8 @@
24/* 24/*
25 * Test program based on Bentley & McIlroy's "Engineering a Sort Function". 25 * Test program based on Bentley & McIlroy's "Engineering a Sort Function".
26 * Uses heapsort(3) to check the results. 26 * Uses heapsort(3) to check the results.
27 * The "killer" input is from:
28 * http://calmerthanyouare.org/2014/06/11/algorithmic-complexity-attacks-and-libc-qsort.html
27 */ 29 */
28 30
29enum distribution { 31enum distribution {
@@ -32,6 +34,7 @@ enum distribution {
32 STAGGER, 34 STAGGER,
33 PLATEAU, 35 PLATEAU,
34 SHUFFLE, 36 SHUFFLE,
37 KILLER,
35 INVALID 38 INVALID
36}; 39};
37 40
@@ -106,6 +109,15 @@ fill_test_array(int *x, int n, int dist, int m)
106 case SHUFFLE: 109 case SHUFFLE:
107 x[i] = arc4random_uniform(m) ? (j += 2) : (k += 2); 110 x[i] = arc4random_uniform(m) ? (j += 2) : (k += 2);
108 break; 111 break;
112 case KILLER:
113 k = n / 2;
114 if (i < k)
115 x[i] = k - i;
116 else if (i > k)
117 x[i] = n + k + 1 - i;
118 else
119 x[i] = k + 1;
120 break;
109 default: 121 default:
110 err(1, "unexpected distribution %d", dist); 122 err(1, "unexpected distribution %d", dist);
111 } 123 }