From 0995f6b340679063fa78e330792f86c94afb34b0 Mon Sep 17 00:00:00 2001 From: bluhm Date: Thu, 27 May 2021 18:18:41 +0000 Subject: [PATCH] Check that libexpat uses arc4random_buf as entropy source. --- regress/lib/libexpat/Makefile | 4 +-- regress/lib/libexpat/entropy/Makefile | 11 +++++++ regress/lib/libexpat/entropy/entropy.c | 40 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 regress/lib/libexpat/entropy/Makefile create mode 100644 regress/lib/libexpat/entropy/entropy.c diff --git a/regress/lib/libexpat/Makefile b/regress/lib/libexpat/Makefile index 16614df6e2a..63c2eaefb98 100644 --- a/regress/lib/libexpat/Makefile +++ b/regress/lib/libexpat/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.1.1.1 2017/06/30 14:56:08 bluhm Exp $ +# $OpenBSD: Makefile,v 1.2 2021/05/27 18:18:41 bluhm Exp $ -SUBDIR= runtests runtestspp benchmark +SUBDIR= runtests runtestspp benchmark entropy .include diff --git a/regress/lib/libexpat/entropy/Makefile b/regress/lib/libexpat/entropy/Makefile new file mode 100644 index 00000000000..522db333040 --- /dev/null +++ b/regress/lib/libexpat/entropy/Makefile @@ -0,0 +1,11 @@ +# $OpenBSD: Makefile,v 1.1 2021/05/27 18:18:41 bluhm Exp $ +# check that libexpat uses arc4random_buf as entropy source + +CLEANFILES= stderr stdout + +run-regress-entropy: entropy + ./entropy 2>stderr >stdout + cat stderr stdout + grep -q arc4random_buf stderr + +.include diff --git a/regress/lib/libexpat/entropy/entropy.c b/regress/lib/libexpat/entropy/entropy.c new file mode 100644 index 00000000000..a227110b75c --- /dev/null +++ b/regress/lib/libexpat/entropy/entropy.c @@ -0,0 +1,40 @@ +/* $OpenBSD: entropy.c,v 1.1 2021/05/27 18:18:41 bluhm Exp $ */ + +/* + * Copyright (c) 2021 Alexander Bluhm + * + * 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 +#include +#include + +int +main(int argc, char *argv[]) +{ + XML_Parser p; + enum XML_Status s; + + if (setenv("EXPAT_ENTROPY_DEBUG", "1", 1) != 0) + err(1, "setenv EXPAT_ENTROPY_DEBUG"); + + p = XML_ParserCreate(NULL); + if (p == NULL) + errx(1, "XML_ParserCreate"); + s = XML_Parse(p, "", 0, 0); + if (s != XML_STATUS_OK) + errx(1, "XML_Parse: %d", s); + + return 0; +} -- 2.20.1