summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorKinichiro Inoguchi <inoguchi@cvs.openbsd.org>2020-03-10 11:10:54 +0000
committerKinichiro Inoguchi <inoguchi@cvs.openbsd.org>2020-03-10 11:10:54 +0000
commit174a661ff4f6b4fb496cdcb7dc659906deaa59d3 (patch)
tree9b069a009ab3ebc1cd8d0570698ee2134a986a84 /regress
parent104d209a6879668359dc77f4e70d4a95474c1d89 (diff)
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@
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libcrypto/base64/base64test.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/regress/lib/libcrypto/base64/base64test.c b/regress/lib/libcrypto/base64/base64test.c
index 1ff3b930023..9b8ac91e72c 100644
--- a/regress/lib/libcrypto/base64/base64test.c
+++ b/regress/lib/libcrypto/base64/base64test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: base64test.c,v 1.6 2019/06/27 04:29:35 deraadt Exp $ */
+/* $OpenBSD: base64test.c,v 1.7 2020/03/10 11:10:53 inoguchi Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -221,7 +221,9 @@ base64_encoding_test(int test_no, struct base64_test *bt, int test_nl)
b64len = 0;
for (i = 0; i < bt->out_len; i++) {
- if (bt->out[i] == '\r' || bt->out[i] == '\n')
+ if ((!test_nl ||
+ (test_nl && (i % 64 != 0 || i == bt->out_len - 1))) &&
+ (bt->out[i] == '\r' || bt->out[i] == '\n'))
continue;
buf[b64len++] = bt->out[i];
}
@@ -273,14 +275,15 @@ base64_decoding_test(int test_no, struct base64_test *bt, int test_nl)
if (buf == NULL)
errx(1, "malloc");
- input = (char *)bt->out;
- inlen = bt->out_len;
-
- if (test_nl)
- inlen = asprintf(&input, "%s\r\n", bt->out);
+ if ((input = malloc(BUF_SIZE)) == NULL)
+ errx(1, "malloc");
- if (inlen == -1)
- errx(1, "asprintf");
+ memcpy(input, bt->out, bt->out_len);
+ inlen = bt->out_len;
+ if (test_nl) {
+ memcpy(&input[bt->out_len], "\r\n", 2);
+ inlen += 2;
+ }
bio_mem = BIO_new_mem_buf(input, inlen);
if (bio_mem == NULL)
@@ -326,8 +329,8 @@ base64_decoding_test(int test_no, struct base64_test *bt, int test_nl)
fprintf(stderr, "0x%x ", buf[i]);
fprintf(stderr, "\n");
fprintf(stderr, " test data: ");
- for (i = 0; i < inlen; i++)
- fprintf(stderr, "0x%x ", input[i]);
+ for (i = 0; i < bt->in_len; i++)
+ fprintf(stderr, "0x%x ", bt->in[i]);
fprintf(stderr, "\n");
failure = 1;
}