summaryrefslogtreecommitdiffstats
path: root/openbsd-compat/regress
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 01:26:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 01:26:58 +0000
commit999ae6be3243c7b4a815247199447b53c39a3d65 (patch)
tree1f35b42b5e5f462d35ba452e4dcfa188ce0543fd /openbsd-compat/regress
parentInitial commit. (diff)
downloadopenssh-999ae6be3243c7b4a815247199447b53c39a3d65.tar.xz
openssh-999ae6be3243c7b4a815247199447b53c39a3d65.zip
Adding upstream version 1:7.9p1.upstream/1%7.9p1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'openbsd-compat/regress')
-rw-r--r--openbsd-compat/regress/Makefile.in36
-rw-r--r--openbsd-compat/regress/closefromtest.c63
-rw-r--r--openbsd-compat/regress/opensslvertest.c69
-rw-r--r--openbsd-compat/regress/snprintftest.c73
-rw-r--r--openbsd-compat/regress/strduptest.c45
-rw-r--r--openbsd-compat/regress/strtonumtest.c80
6 files changed, 366 insertions, 0 deletions
diff --git a/openbsd-compat/regress/Makefile.in b/openbsd-compat/regress/Makefile.in
new file mode 100644
index 0000000..529331b
--- /dev/null
+++ b/openbsd-compat/regress/Makefile.in
@@ -0,0 +1,36 @@
+sysconfdir=@sysconfdir@
+piddir=@piddir@
+srcdir=@srcdir@
+top_srcdir=@top_srcdir@
+
+VPATH=@srcdir@
+CC=@CC@
+LD=@LD@
+CFLAGS=@CFLAGS@
+CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/.. @CPPFLAGS@ @DEFS@
+EXEEXT=@EXEEXT@
+LIBCOMPAT=../libopenbsd-compat.a
+LIBS=@LIBS@
+LDFLAGS=@LDFLAGS@ $(LIBCOMPAT)
+
+TESTPROGS=closefromtest$(EXEEXT) snprintftest$(EXEEXT) strduptest$(EXEEXT) \
+ strtonumtest$(EXEEXT) opensslvertest$(EXEEXT)
+
+all: t-exec ${OTHERTESTS}
+
+%$(EXEEXT): %.c $(LIBCOMPAT)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< $(LIBCOMPAT) $(LIBS)
+
+t-exec: $(TESTPROGS)
+ @echo running compat regress tests
+ @for TEST in ""$?; do \
+ echo "run test $${TEST}" ... 1>&2; \
+ ./$${TEST}$(EXEEXT) || exit $$? ; \
+ done
+ @echo finished compat regress tests
+
+clean:
+ rm -f *.o *.a core $(TESTPROGS) valid.out
+
+distclean: clean
+ rm -f Makefile *~
diff --git a/openbsd-compat/regress/closefromtest.c b/openbsd-compat/regress/closefromtest.c
new file mode 100644
index 0000000..82ffeb9
--- /dev/null
+++ b/openbsd-compat/regress/closefromtest.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2006 Darren Tucker
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define NUM_OPENS 10
+
+int closefrom(int);
+
+void
+fail(char *msg)
+{
+ fprintf(stderr, "closefrom: %s\n", msg);
+ exit(1);
+}
+
+int
+main(void)
+{
+ int i, max, fds[NUM_OPENS];
+ char buf[512];
+
+ for (i = 0; i < NUM_OPENS; i++)
+ if ((fds[i] = open("/dev/null", O_RDONLY)) == -1)
+ exit(0); /* can't test */
+ max = i - 1;
+
+ /* should close last fd only */
+ closefrom(fds[max]);
+ if (close(fds[max]) != -1)
+ fail("failed to close highest fd");
+
+ /* make sure we can still use remaining descriptors */
+ for (i = 0; i < max; i++)
+ if (read(fds[i], buf, sizeof(buf)) == -1)
+ fail("closed descriptors it should not have");
+
+ /* should close all fds */
+ closefrom(fds[0]);
+ for (i = 0; i < NUM_OPENS; i++)
+ if (close(fds[i]) != -1)
+ fail("failed to close from lowest fd");
+ return 0;
+}
diff --git a/openbsd-compat/regress/opensslvertest.c b/openbsd-compat/regress/opensslvertest.c
new file mode 100644
index 0000000..5d019b5
--- /dev/null
+++ b/openbsd-compat/regress/opensslvertest.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014 Darren Tucker
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int ssh_compatible_openssl(long, long);
+
+struct version_test {
+ long headerver;
+ long libver;
+ int result;
+} version_tests[] = {
+ /* built with 0.9.8b release headers */
+ { 0x0090802fL, 0x0090802fL, 1}, /* exact match */
+ { 0x0090802fL, 0x0090804fL, 1}, /* newer library fix version: ok */
+ { 0x0090802fL, 0x0090801fL, 1}, /* older library fix version: ok */
+ { 0x0090802fL, 0x0090702fL, 0}, /* older library minor version: NO */
+ { 0x0090802fL, 0x0090902fL, 0}, /* newer library minor version: NO */
+ { 0x0090802fL, 0x0080802fL, 0}, /* older library major version: NO */
+ { 0x0090802fL, 0x1000100fL, 0}, /* newer library major version: NO */
+
+ /* built with 1.0.1b release headers */
+ { 0x1000101fL, 0x1000101fL, 1},/* exact match */
+ { 0x1000101fL, 0x1000102fL, 1}, /* newer library patch version: ok */
+ { 0x1000101fL, 0x1000100fL, 1}, /* older library patch version: ok */
+ { 0x1000101fL, 0x1000201fL, 1}, /* newer library fix version: ok */
+ { 0x1000101fL, 0x1000001fL, 0}, /* older library fix version: NO */
+ { 0x1000101fL, 0x1010101fL, 0}, /* newer library minor version: NO */
+ { 0x1000101fL, 0x0000101fL, 0}, /* older library major version: NO */
+ { 0x1000101fL, 0x2000101fL, 0}, /* newer library major version: NO */
+};
+
+void
+fail(long hver, long lver, int result)
+{
+ fprintf(stderr, "opensslver: header %lx library %lx != %d \n", hver, lver, result);
+ exit(1);
+}
+
+int
+main(void)
+{
+ unsigned int i;
+ int res;
+ long hver, lver;
+
+ for (i = 0; i < sizeof(version_tests) / sizeof(version_tests[0]); i++) {
+ hver = version_tests[i].headerver;
+ lver = version_tests[i].libver;
+ res = version_tests[i].result;
+ if (ssh_compatible_openssl(hver, lver) != res)
+ fail(hver, lver, res);
+ }
+ exit(0);
+}
diff --git a/openbsd-compat/regress/snprintftest.c b/openbsd-compat/regress/snprintftest.c
new file mode 100644
index 0000000..4ca63e1
--- /dev/null
+++ b/openbsd-compat/regress/snprintftest.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2005 Darren Tucker
+ * Copyright (c) 2005 Damien Miller
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define BUFSZ 2048
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+static int failed = 0;
+
+static void
+fail(const char *m)
+{
+ fprintf(stderr, "snprintftest: %s\n", m);
+ failed = 1;
+}
+
+int x_snprintf(char *str, size_t count, const char *fmt, ...)
+{
+ size_t ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vsnprintf(str, count, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+
+int
+main(void)
+{
+ char b[5];
+ char *src;
+
+ snprintf(b,5,"123456789");
+ if (b[4] != '\0')
+ fail("snprintf does not correctly terminate long strings");
+
+ /* check for read overrun on unterminated string */
+ if ((src = malloc(BUFSZ)) == NULL) {
+ fail("malloc failed");
+ } else {
+ memset(src, 'a', BUFSZ);
+ snprintf(b, sizeof(b), "%.*s", 1, src);
+ if (strcmp(b, "a") != 0)
+ fail("failed with length limit '%%.s'");
+ }
+
+ /* check that snprintf and vsnprintf return sane values */
+ if (snprintf(b, 1, "%s %d", "hello", 12345) != 11)
+ fail("snprintf does not return required length");
+ if (x_snprintf(b, 1, "%s %d", "hello", 12345) != 11)
+ fail("vsnprintf does not return required length");
+
+ return failed;
+}
diff --git a/openbsd-compat/regress/strduptest.c b/openbsd-compat/regress/strduptest.c
new file mode 100644
index 0000000..7f6d779
--- /dev/null
+++ b/openbsd-compat/regress/strduptest.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2005 Darren Tucker
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+static int fail = 0;
+
+void
+test(const char *a)
+{
+ char *b;
+
+ b = strdup(a);
+ if (b == 0) {
+ fail = 1;
+ return;
+ }
+ if (strcmp(a, b) != 0)
+ fail = 1;
+ free(b);
+}
+
+int
+main(void)
+{
+ test("");
+ test("a");
+ test("\0");
+ test("abcdefghijklmnopqrstuvwxyz");
+ return fail;
+}
diff --git a/openbsd-compat/regress/strtonumtest.c b/openbsd-compat/regress/strtonumtest.c
new file mode 100644
index 0000000..50ca5bd
--- /dev/null
+++ b/openbsd-compat/regress/strtonumtest.c
@@ -0,0 +1,80 @@
+/* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */
+/*
+ * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* OPENBSD ORIGINAL: regress/lib/libc/strtonum/strtonumtest.c */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/* LLONG_MAX is known as LONGLONG_MAX on AIX */
+#if defined(LONGLONG_MAX) && !defined(LLONG_MAX)
+# define LLONG_MAX LONGLONG_MAX
+# define LLONG_MIN LONGLONG_MIN
+#endif
+
+/* LLONG_MAX is known as LONG_LONG_MAX on HP-UX */
+#if defined(LONG_LONG_MAX) && !defined(LLONG_MAX)
+# define LLONG_MAX LONG_LONG_MAX
+# define LLONG_MIN LONG_LONG_MIN
+#endif
+
+long long strtonum(const char *, long long, long long, const char **);
+
+int fail;
+
+void
+test(const char *p, long long lb, long long ub, int ok)
+{
+ long long val;
+ const char *q;
+
+ val = strtonum(p, lb, ub, &q);
+ if (ok && q != NULL) {
+ fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub);
+ fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q);
+ fail = 1;
+ } else if (!ok && q == NULL) {
+ fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val);
+ fprintf(stderr, "NUMBER ACCEPTED\n");
+ fail = 1;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ test("1", 0, 10, 1);
+ test("0", -2, 5, 1);
+ test("0", 2, 5, 0);
+ test("0", 2, LLONG_MAX, 0);
+ test("-2", 0, LLONG_MAX, 0);
+ test("0", -5, LLONG_MAX, 1);
+ test("-3", -3, LLONG_MAX, 1);
+ test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1);
+ test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1);
+ test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0);
+ test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0);
+ test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
+ test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
+ test("-2", 10, -1, 0);
+ test("-2", -10, -1, 1);
+ test("-20", -10, -1, 0);
+ test("20", -10, -1, 0);
+
+ return (fail);
+}
+