summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/Makefile2
-rw-r--r--regress/unittests/test_helper/fuzz.c83
-rw-r--r--regress/unittests/test_helper/test_helper.c26
-rw-r--r--regress/unittests/test_helper/test_helper.h3
4 files changed, 92 insertions, 22 deletions
diff --git a/regress/Makefile b/regress/Makefile
index 2e068e94a..3d32857c6 100644
--- a/regress/Makefile
+++ b/regress/Makefile
@@ -96,7 +96,7 @@ CLEANFILES= t2.out t3.out t6.out1 t6.out2 t7.out t7.out.pub copy.1 copy.2 \
96 regress.log failed-regress.log ssh-log-wrapper.sh \ 96 regress.log failed-regress.log ssh-log-wrapper.sh \
97 sftp-server.sh sftp-server.log sftp.log setuid-allowed \ 97 sftp-server.sh sftp-server.log sftp.log setuid-allowed \
98 data ed25519-agent ed25519-agent.pub key.ed25519-512 \ 98 data ed25519-agent ed25519-agent.pub key.ed25519-512 \
99 key.ed25519-512.pub netcat 99 key.ed25519-512.pub netcat host_krl_* host_revoked_* user_*key*
100 100
101SUDO_CLEAN+= /var/run/testdata_${USER} /var/run/keycommand_${USER} 101SUDO_CLEAN+= /var/run/testdata_${USER} /var/run/keycommand_${USER}
102 102
diff --git a/regress/unittests/test_helper/fuzz.c b/regress/unittests/test_helper/fuzz.c
index d8e1b7ec0..963bce3dc 100644
--- a/regress/unittests/test_helper/fuzz.c
+++ b/regress/unittests/test_helper/fuzz.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: fuzz.c,v 1.4 2014/11/19 13:35:37 krw Exp $ */ 1/* $OpenBSD: fuzz.c,v 1.5 2015/01/13 14:51:51 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -20,6 +20,7 @@
20#include "includes.h" 20#include "includes.h"
21 21
22#include <sys/types.h> 22#include <sys/types.h>
23#include <sys/uio.h>
23 24
24#include <assert.h> 25#include <assert.h>
25#include <ctype.h> 26#include <ctype.h>
@@ -29,8 +30,11 @@
29#endif 30#endif
30#include <stdlib.h> 31#include <stdlib.h>
31#include <string.h> 32#include <string.h>
33#include <signal.h>
34#include <unistd.h>
32 35
33#include "test_helper.h" 36#include "test_helper.h"
37#include "atomicio.h"
34 38
35/* #define FUZZ_DEBUG */ 39/* #define FUZZ_DEBUG */
36 40
@@ -95,59 +99,73 @@ fuzz_ntop(u_int n)
95 } 99 }
96} 100}
97 101
98void 102static int
99fuzz_dump(struct fuzz *fuzz) 103fuzz_fmt(struct fuzz *fuzz, char *s, size_t n)
100{ 104{
101 u_char *p = fuzz_ptr(fuzz); 105 if (fuzz == NULL)
102 size_t i, j, len = fuzz_len(fuzz); 106 return -1;
103 107
104 switch (fuzz->strategy) { 108 switch (fuzz->strategy) {
105 case FUZZ_1_BIT_FLIP: 109 case FUZZ_1_BIT_FLIP:
106 fprintf(stderr, "%s case %zu of %zu (bit: %zu)\n", 110 snprintf(s, n, "%s case %zu of %zu (bit: %zu)\n",
107 fuzz_ntop(fuzz->strategy), 111 fuzz_ntop(fuzz->strategy),
108 fuzz->o1, fuzz->slen * 8, fuzz->o1); 112 fuzz->o1, fuzz->slen * 8, fuzz->o1);
109 break; 113 return 0;
110 case FUZZ_2_BIT_FLIP: 114 case FUZZ_2_BIT_FLIP:
111 fprintf(stderr, "%s case %llu of %llu (bits: %zu, %zu)\n", 115 snprintf(s, n, "%s case %llu of %llu (bits: %zu, %zu)\n",
112 fuzz_ntop(fuzz->strategy), 116 fuzz_ntop(fuzz->strategy),
113 (((fuzz_ullong)fuzz->o2) * fuzz->slen * 8) + fuzz->o1, 117 (((fuzz_ullong)fuzz->o2) * fuzz->slen * 8) + fuzz->o1,
114 ((fuzz_ullong)fuzz->slen * 8) * fuzz->slen * 8, 118 ((fuzz_ullong)fuzz->slen * 8) * fuzz->slen * 8,
115 fuzz->o1, fuzz->o2); 119 fuzz->o1, fuzz->o2);
116 break; 120 return 0;
117 case FUZZ_1_BYTE_FLIP: 121 case FUZZ_1_BYTE_FLIP:
118 fprintf(stderr, "%s case %zu of %zu (byte: %zu)\n", 122 snprintf(s, n, "%s case %zu of %zu (byte: %zu)\n",
119 fuzz_ntop(fuzz->strategy), 123 fuzz_ntop(fuzz->strategy),
120 fuzz->o1, fuzz->slen, fuzz->o1); 124 fuzz->o1, fuzz->slen, fuzz->o1);
121 break; 125 return 0;
122 case FUZZ_2_BYTE_FLIP: 126 case FUZZ_2_BYTE_FLIP:
123 fprintf(stderr, "%s case %llu of %llu (bytes: %zu, %zu)\n", 127 snprintf(s, n, "%s case %llu of %llu (bytes: %zu, %zu)\n",
124 fuzz_ntop(fuzz->strategy), 128 fuzz_ntop(fuzz->strategy),
125 (((fuzz_ullong)fuzz->o2) * fuzz->slen) + fuzz->o1, 129 (((fuzz_ullong)fuzz->o2) * fuzz->slen) + fuzz->o1,
126 ((fuzz_ullong)fuzz->slen) * fuzz->slen, 130 ((fuzz_ullong)fuzz->slen) * fuzz->slen,
127 fuzz->o1, fuzz->o2); 131 fuzz->o1, fuzz->o2);
128 break; 132 return 0;
129 case FUZZ_TRUNCATE_START: 133 case FUZZ_TRUNCATE_START:
130 fprintf(stderr, "%s case %zu of %zu (offset: %zu)\n", 134 snprintf(s, n, "%s case %zu of %zu (offset: %zu)\n",
131 fuzz_ntop(fuzz->strategy), 135 fuzz_ntop(fuzz->strategy),
132 fuzz->o1, fuzz->slen, fuzz->o1); 136 fuzz->o1, fuzz->slen, fuzz->o1);
133 break; 137 return 0;
134 case FUZZ_TRUNCATE_END: 138 case FUZZ_TRUNCATE_END:
135 fprintf(stderr, "%s case %zu of %zu (offset: %zu)\n", 139 snprintf(s, n, "%s case %zu of %zu (offset: %zu)\n",
136 fuzz_ntop(fuzz->strategy), 140 fuzz_ntop(fuzz->strategy),
137 fuzz->o1, fuzz->slen, fuzz->o1); 141 fuzz->o1, fuzz->slen, fuzz->o1);
138 break; 142 return 0;
139 case FUZZ_BASE64: 143 case FUZZ_BASE64:
140 assert(fuzz->o2 < sizeof(fuzz_b64chars) - 1); 144 assert(fuzz->o2 < sizeof(fuzz_b64chars) - 1);
141 fprintf(stderr, "%s case %llu of %llu (offset: %zu char: %c)\n", 145 snprintf(s, n, "%s case %llu of %llu (offset: %zu char: %c)\n",
142 fuzz_ntop(fuzz->strategy), 146 fuzz_ntop(fuzz->strategy),
143 (fuzz->o1 * (fuzz_ullong)64) + fuzz->o2, 147 (fuzz->o1 * (fuzz_ullong)64) + fuzz->o2,
144 fuzz->slen * (fuzz_ullong)64, fuzz->o1, 148 fuzz->slen * (fuzz_ullong)64, fuzz->o1,
145 fuzz_b64chars[fuzz->o2]); 149 fuzz_b64chars[fuzz->o2]);
146 break; 150 return 0;
147 default: 151 default:
152 return -1;
148 abort(); 153 abort();
149 } 154 }
155}
156
157void
158fuzz_dump(struct fuzz *fuzz)
159{
160 u_char *p = fuzz_ptr(fuzz);
161 size_t i, j, len = fuzz_len(fuzz);
162 char buf[256];
150 163
164 if (fuzz_fmt(fuzz, buf, sizeof(buf)) != 0) {
165 fprintf(stderr, "%s: fuzz invalid\n", __func__);
166 abort();
167 }
168 fputs(buf, stderr);
151 fprintf(stderr, "fuzz context %p len = %zu\n", fuzz, len); 169 fprintf(stderr, "fuzz context %p len = %zu\n", fuzz, len);
152 for (i = 0; i < len; i += 16) { 170 for (i = 0; i < len; i += 16) {
153 fprintf(stderr, "%.4zd: ", i); 171 fprintf(stderr, "%.4zd: ", i);
@@ -170,6 +188,23 @@ fuzz_dump(struct fuzz *fuzz)
170 } 188 }
171} 189}
172 190
191#ifdef SIGINFO
192static struct fuzz *last_fuzz;
193
194static void
195siginfo(int unused __unused)
196{
197 char buf[256];
198
199 test_info(buf, sizeof(buf));
200 atomicio(vwrite, STDERR_FILENO, buf, strlen(buf));
201 if (last_fuzz != NULL) {
202 fuzz_fmt(last_fuzz, buf, sizeof(buf));
203 atomicio(vwrite, STDERR_FILENO, buf, strlen(buf));
204 }
205}
206#endif
207
173struct fuzz * 208struct fuzz *
174fuzz_begin(u_int strategies, const void *p, size_t l) 209fuzz_begin(u_int strategies, const void *p, size_t l)
175{ 210{
@@ -189,6 +224,12 @@ fuzz_begin(u_int strategies, const void *p, size_t l)
189 FUZZ_DBG(("begin, ret = %p", ret)); 224 FUZZ_DBG(("begin, ret = %p", ret));
190 225
191 fuzz_next(ret); 226 fuzz_next(ret);
227
228#ifdef SIGINFO
229 last_fuzz = ret;
230 signal(SIGINFO, siginfo);
231#endif
232
192 return ret; 233 return ret;
193} 234}
194 235
@@ -196,6 +237,10 @@ void
196fuzz_cleanup(struct fuzz *fuzz) 237fuzz_cleanup(struct fuzz *fuzz)
197{ 238{
198 FUZZ_DBG(("cleanup, fuzz = %p", fuzz)); 239 FUZZ_DBG(("cleanup, fuzz = %p", fuzz));
240#ifdef SIGINFO
241 last_fuzz = NULL;
242 signal(SIGINFO, SIG_DFL);
243#endif
199 assert(fuzz != NULL); 244 assert(fuzz != NULL);
200 assert(fuzz->seed != NULL); 245 assert(fuzz->seed != NULL);
201 assert(fuzz->fuzzed != NULL); 246 assert(fuzz->fuzzed != NULL);
diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c
index d0bc67833..6f7f381c7 100644
--- a/regress/unittests/test_helper/test_helper.c
+++ b/regress/unittests/test_helper/test_helper.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_helper.c,v 1.2 2014/05/02 09:41:32 andre Exp $ */ 1/* $OpenBSD: test_helper.c,v 1.3 2015/01/13 14:51:51 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -21,6 +21,7 @@
21 21
22#include <sys/types.h> 22#include <sys/types.h>
23#include <sys/param.h> 23#include <sys/param.h>
24#include <sys/uio.h>
24 25
25#include <fcntl.h> 26#include <fcntl.h>
26#include <stdio.h> 27#include <stdio.h>
@@ -31,6 +32,7 @@
31#include <string.h> 32#include <string.h>
32#include <assert.h> 33#include <assert.h>
33#include <unistd.h> 34#include <unistd.h>
35#include <signal.h>
34 36
35#include <openssl/bn.h> 37#include <openssl/bn.h>
36 38
@@ -39,6 +41,7 @@
39#endif 41#endif
40 42
41#include "test_helper.h" 43#include "test_helper.h"
44#include "atomicio.h"
42 45
43#define TEST_CHECK_INT(r, pred) do { \ 46#define TEST_CHECK_INT(r, pred) do { \
44 switch (pred) { \ 47 switch (pred) { \
@@ -180,6 +183,24 @@ test_data_file(const char *name)
180} 183}
181 184
182void 185void
186test_info(char *s, size_t len)
187{
188 snprintf(s, len, "In test %u - \"%s\"\n", test_number,
189 active_test_name == NULL ? "<none>" : active_test_name);
190}
191
192#ifdef SIGINFO
193static void
194siginfo(int unused __unused)
195{
196 char buf[256];
197
198 test_info(buf, sizeof(buf));
199 atomicio(vwrite, STDERR_FILENO, buf, strlen(buf));
200}
201#endif
202
203void
183test_start(const char *n) 204test_start(const char *n)
184{ 205{
185 assert(active_test_name == NULL); 206 assert(active_test_name == NULL);
@@ -187,6 +208,9 @@ test_start(const char *n)
187 if (verbose_mode) 208 if (verbose_mode)
188 printf("test %u - \"%s\": ", test_number, active_test_name); 209 printf("test %u - \"%s\": ", test_number, active_test_name);
189 test_number++; 210 test_number++;
211#ifdef SIGINFO
212 signal(SIGINFO, siginfo);
213#endif
190} 214}
191 215
192void 216void
diff --git a/regress/unittests/test_helper/test_helper.h b/regress/unittests/test_helper/test_helper.h
index a398c615f..b6a39ea3e 100644
--- a/regress/unittests/test_helper/test_helper.h
+++ b/regress/unittests/test_helper/test_helper.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_helper.h,v 1.3 2014/05/02 09:41:32 andre Exp $ */ 1/* $OpenBSD: test_helper.h,v 1.4 2015/01/13 14:51:51 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -40,6 +40,7 @@ void tests(void);
40 40
41const char *test_data_file(const char *name); 41const char *test_data_file(const char *name);
42void test_start(const char *n); 42void test_start(const char *n);
43void test_info(char *s, size_t len);
43void set_onerror_func(test_onerror_func_t *f, void *ctx); 44void set_onerror_func(test_onerror_func_t *f, void *ctx);
44void test_done(void); 45void test_done(void);
45void ssl_err_check(const char *file, int line); 46void ssl_err_check(const char *file, int line);