From 174a661ff4f6b4fb496cdcb7dc659906deaa59d3 Mon Sep 17 00:00:00 2001 From: Kinichiro Inoguchi Date: Tue, 10 Mar 2020 11:10:54 +0000 Subject: 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@ --- regress/lib/libcrypto/base64/base64test.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'regress/lib') 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 * @@ -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; } -- cgit v1.2.3