summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinoguchi <>2020-03-10 11:10:53 +0000
committerinoguchi <>2020-03-10 11:10:53 +0000
commit9feddb8f718ed9f6bea887f11ed40e629a8d07e8 (patch)
treef6613cfabf9c3b22ea88adafc3e0eef8dc13fe05
parentf06e55459ad96981abf401d5ccbb700ef0618af8 (diff)
downloadopenbsd-9feddb8f718ed9f6bea887f11ed40e629a8d07e8.tar.gz
openbsd-9feddb8f718ed9f6bea887f11ed40e629a8d07e8.tar.bz2
openbsd-9feddb8f718ed9f6bea887f11ed40e629a8d07e8.zip
Modify regress base64test.c
- Don't remove multi line CR/LF from bt->out when NL mode base64_encoding_test removes CR/LF from bt->out to compare with the encoding result. This is fine with NO NL mode, but it goes wrong with NL mode if encoding result is larger than 64 and multi line, like below. "eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4\neHh4eHh4eHh4eHh4\n" - Use memcpy instead of asprintf to avoid lost '\0' at the end of data This test data loses trailing '\0' if using asprintf. "\x61\x47\x56\x73\x62\x47\x38\x3d\x0a\x00" - Print original data if decoding result comparison fails This change is not for importing test data, but I just notice. It prints bt->out if fail to memcmp bt->in with decoding result. ok bcook@ tb@
-rw-r--r--src/regress/lib/libcrypto/base64/base64test.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/regress/lib/libcrypto/base64/base64test.c b/src/regress/lib/libcrypto/base64/base64test.c
index 1ff3b93002..9b8ac91e72 100644
--- a/src/regress/lib/libcrypto/base64/base64test.c
+++ b/src/regress/lib/libcrypto/base64/base64test.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: base64test.c,v 1.6 2019/06/27 04:29:35 deraadt Exp $ */ 1/* $OpenBSD: base64test.c,v 1.7 2020/03/10 11:10:53 inoguchi Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -221,7 +221,9 @@ base64_encoding_test(int test_no, struct base64_test *bt, int test_nl)
221 221
222 b64len = 0; 222 b64len = 0;
223 for (i = 0; i < bt->out_len; i++) { 223 for (i = 0; i < bt->out_len; i++) {
224 if (bt->out[i] == '\r' || bt->out[i] == '\n') 224 if ((!test_nl ||
225 (test_nl && (i % 64 != 0 || i == bt->out_len - 1))) &&
226 (bt->out[i] == '\r' || bt->out[i] == '\n'))
225 continue; 227 continue;
226 buf[b64len++] = bt->out[i]; 228 buf[b64len++] = bt->out[i];
227 } 229 }
@@ -273,14 +275,15 @@ base64_decoding_test(int test_no, struct base64_test *bt, int test_nl)
273 if (buf == NULL) 275 if (buf == NULL)
274 errx(1, "malloc"); 276 errx(1, "malloc");
275 277
276 input = (char *)bt->out; 278 if ((input = malloc(BUF_SIZE)) == NULL)
277 inlen = bt->out_len; 279 errx(1, "malloc");
278
279 if (test_nl)
280 inlen = asprintf(&input, "%s\r\n", bt->out);
281 280
282 if (inlen == -1) 281 memcpy(input, bt->out, bt->out_len);
283 errx(1, "asprintf"); 282 inlen = bt->out_len;
283 if (test_nl) {
284 memcpy(&input[bt->out_len], "\r\n", 2);
285 inlen += 2;
286 }
284 287
285 bio_mem = BIO_new_mem_buf(input, inlen); 288 bio_mem = BIO_new_mem_buf(input, inlen);
286 if (bio_mem == NULL) 289 if (bio_mem == NULL)
@@ -326,8 +329,8 @@ base64_decoding_test(int test_no, struct base64_test *bt, int test_nl)
326 fprintf(stderr, "0x%x ", buf[i]); 329 fprintf(stderr, "0x%x ", buf[i]);
327 fprintf(stderr, "\n"); 330 fprintf(stderr, "\n");
328 fprintf(stderr, " test data: "); 331 fprintf(stderr, " test data: ");
329 for (i = 0; i < inlen; i++) 332 for (i = 0; i < bt->in_len; i++)
330 fprintf(stderr, "0x%x ", input[i]); 333 fprintf(stderr, "0x%x ", bt->in[i]);
331 fprintf(stderr, "\n"); 334 fprintf(stderr, "\n");
332 failure = 1; 335 failure = 1;
333 } 336 }