summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2014-06-22 14:30:52 +0000
committerjsing <>2014-06-22 14:30:52 +0000
commitfc342088a9e9234b5e22294af9d7a3b490705097 (patch)
tree2c9edbbbc900ed48351ad4bd3156f414bde51e0a
parent8f1d42a3982df1db0e527c3b64d5d055d78c92ca (diff)
downloadopenbsd-fc342088a9e9234b5e22294af9d7a3b490705097.tar.gz
openbsd-fc342088a9e9234b5e22294af9d7a3b490705097.tar.bz2
openbsd-fc342088a9e9234b5e22294af9d7a3b490705097.zip
Add a skeleton regress for crypto/bio, which currently only covers
BIO_get_port() and fails since the current code believes that "-1" is a valid port.
-rw-r--r--src/regress/lib/libcrypto/Makefile3
-rw-r--r--src/regress/lib/libcrypto/bio/Makefile9
-rw-r--r--src/regress/lib/libcrypto/bio/biotest.c83
3 files changed, 94 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/Makefile b/src/regress/lib/libcrypto/Makefile
index d9bd92f637..19cb9ab4ad 100644
--- a/src/regress/lib/libcrypto/Makefile
+++ b/src/regress/lib/libcrypto/Makefile
@@ -1,10 +1,11 @@
1# $OpenBSD: Makefile,v 1.13 2014/06/22 14:28:07 jsing Exp $ 1# $OpenBSD: Makefile,v 1.14 2014/06/22 14:30:52 jsing Exp $
2 2
3SUBDIR= \ 3SUBDIR= \
4 aead \ 4 aead \
5 aeswrap \ 5 aeswrap \
6 base64 \ 6 base64 \
7 bf \ 7 bf \
8 bio \
8 bn \ 9 bn \
9 cast \ 10 cast \
10 chacha \ 11 chacha \
diff --git a/src/regress/lib/libcrypto/bio/Makefile b/src/regress/lib/libcrypto/bio/Makefile
new file mode 100644
index 0000000000..9955cd4b8f
--- /dev/null
+++ b/src/regress/lib/libcrypto/bio/Makefile
@@ -0,0 +1,9 @@
1# $OpenBSD: Makefile,v 1.1 2014/06/22 14:30:52 jsing Exp $
2
3PROG= biotest
4LDADD= -lcrypto
5DPADD= ${LIBCRYPTO}
6WARNINGS= Yes
7CFLAGS+= -Werror
8
9.include <bsd.regress.mk>
diff --git a/src/regress/lib/libcrypto/bio/biotest.c b/src/regress/lib/libcrypto/bio/biotest.c
new file mode 100644
index 0000000000..3639cb1f36
--- /dev/null
+++ b/src/regress/lib/libcrypto/bio/biotest.c
@@ -0,0 +1,83 @@
1/* $OpenBSD: biotest.c,v 1.1 2014/06/22 14:30:52 jsing Exp $ */
2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19
20#include <openssl/bio.h>
21#include <openssl/err.h>
22
23struct bio_get_port_test {
24 char *input;
25 unsigned short port;
26 int ret;
27};
28
29struct bio_get_port_test bio_get_port_tests[] = {
30 {NULL, 0, 0},
31 {"", 0, 0},
32 {"-1", 0, 0},
33 {"0", 0, 1},
34 {"1", 1, 1},
35 {"12345", 12345, 1},
36 {"65535", 65535, 1},
37 {"65536", 0, 0},
38 {"999999999999", 0, 0},
39 {"xyzzy", 0, 0},
40 {"https", 443, 1},
41 {"imaps", 993, 1},
42 {"telnet", 23, 1},
43};
44
45#define N_BIO_GET_PORT_TESTS \
46 (sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests))
47
48static int
49do_bio_get_port_tests(void)
50{
51 struct bio_get_port_test *bgpt;
52 unsigned short port;
53 int failed = 0;
54 size_t i;
55 int ret;
56
57 for (i = 0; i < N_BIO_GET_PORT_TESTS; i++) {
58 bgpt = &bio_get_port_tests[i];
59 port = 0;
60
61 ret = BIO_get_port(bgpt->input, &port);
62 if (ret != bgpt->ret) {
63 fprintf(stderr, "FAIL: test %zi (\"%s\") %s, want %s\n",
64 i, bgpt->input, ret ? "success" : "failure",
65 bgpt->ret ? "success" : "failure");
66 failed = 1;
67 continue;
68 }
69 if (ret && port != bgpt->port) {
70 fprintf(stderr, "FAIL: test %zi (\"%s\") returned port "
71 "%u != %u\n", i, bgpt->input, port, bgpt->port);
72 failed = 1;
73 }
74 }
75
76 return failed;
77}
78
79int
80main(int argc, char **argv)
81{
82 return do_bio_get_port_tests();
83}