From 214007faffa9c103223cccc1c50cdb975a729b68 Mon Sep 17 00:00:00 2001 From: Lauri Tirkkonen Date: Sat, 27 Jan 2018 20:47:56 +0200 Subject: [PATCH] remove compat strtonum implementations --- bin/mandoc/Makefile | 2 +- bin/mandoc/compat_strtonum.c | 76 ----------------------------------- bin/mandoc/config.h | 4 +- bin/nc/compat.mk | 2 +- bin/openssl/compat.mk | 3 +- bin/pax/Makefile | 2 +- bin/pax/strtonum.c | 65 ------------------------------ lib/libcrypto/compat/include/stdlib.h | 41 ------------------- lib/libcrypto/compat/strtonum.c | 65 ------------------------------ 9 files changed, 5 insertions(+), 255 deletions(-) delete mode 100644 bin/mandoc/compat_strtonum.c delete mode 100644 bin/pax/strtonum.c delete mode 100644 lib/libcrypto/compat/include/stdlib.h delete mode 100644 lib/libcrypto/compat/strtonum.c diff --git a/bin/mandoc/Makefile b/bin/mandoc/Makefile index cb15c81ead..a47bb7ca16 100644 --- a/bin/mandoc/Makefile +++ b/bin/mandoc/Makefile @@ -15,7 +15,7 @@ SRCS+= mdoc_markdown.c SRCS+= dbm_map.c dbm.c dba_write.c dba_array.c dba.c dba_read.c SRCS+= manpath.c mandocdb.c mansearch.c -SRCS+= lib.c compat_ohash.c compat_strtonum.c +SRCS+= lib.c compat_ohash.c LDADD+= -lz CFLAGS+= -std=gnu99 diff --git a/bin/mandoc/compat_strtonum.c b/bin/mandoc/compat_strtonum.c deleted file mode 100644 index 628e5d51b8..0000000000 --- a/bin/mandoc/compat_strtonum.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "config.h" - -#if HAVE_STRTONUM - -int dummy; - -#else - -/* $Id: compat_strtonum.c,v 1.1 2015/02/16 14:56:22 schwarze Exp $ */ -/* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */ - -/* - * Copyright (c) 2004 Ted Unangst and Todd Miller - * All rights reserved. - * - * 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 - -#define INVALID 1 -#define TOOSMALL 2 -#define TOOLARGE 3 - -long long -strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) -{ - long long ll = 0; - int error = 0; - char *ep; - struct errval { - const char *errstr; - int err; - } ev[4] = { - { NULL, 0 }, - { "invalid", EINVAL }, - { "too small", ERANGE }, - { "too large", ERANGE }, - }; - - ev[0].err = errno; - errno = 0; - if (minval > maxval) { - error = INVALID; - } else { - ll = strtoll(numstr, &ep, 10); - if (numstr == ep || *ep != '\0') - error = INVALID; - else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) - error = TOOSMALL; - else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) - error = TOOLARGE; - } - if (errstrp != NULL) - *errstrp = ev[error].errstr; - errno = ev[error].err; - if (error) - ll = 0; - - return (ll); -} - -#endif /* !HAVE_STRTONUM */ diff --git a/bin/mandoc/config.h b/bin/mandoc/config.h index 2fd82bed8c..a55f3049ae 100644 --- a/bin/mandoc/config.h +++ b/bin/mandoc/config.h @@ -40,7 +40,7 @@ #define HAVE_STRLCPY 1 #define HAVE_STRPTIME 1 #define HAVE_STRSEP 1 -#define HAVE_STRTONUM 0 +#define HAVE_STRTONUM 1 #define HAVE_SYS_ENDIAN 0 #define HAVE_VASPRINTF 1 #define HAVE_WCHAR 1 @@ -51,5 +51,3 @@ #define BINM_MAN "man" #define BINM_SOELIM "soelim" #define BINM_WHATIS "whatis" - -extern long long strtonum(const char *, long long, long long, const char **); diff --git a/bin/nc/compat.mk b/bin/nc/compat.mk index 7343164491..1531a42571 100644 --- a/bin/nc/compat.mk +++ b/bin/nc/compat.mk @@ -1,7 +1,7 @@ .include LCRYPTO_SRC= ${SRCTOP}/lib/libcrypto CPPFLAGS+= -I${.CURDIR}/compat/include -I${LCRYPTO_SRC}/compat/include -SRCS+= readpassphrase.c strtonum.c base64.c +SRCS+= readpassphrase.c base64.c .PATH: ${.CURDIR}/compat ${LCRYPTO_SRC}/compat # ssl, crypto are only needed indirectly and cause check_rtime warnings, so # override LDADD here diff --git a/bin/openssl/compat.mk b/bin/openssl/compat.mk index b478e2df6d..fc863a7c6c 100644 --- a/bin/openssl/compat.mk +++ b/bin/openssl/compat.mk @@ -1,5 +1,4 @@ .include LCRYPTO_SRC= ${SRCTOP}/lib/libcrypto +# pledge CPPFLAGS+= -I${LCRYPTO_SRC}/compat/include -SRCS+= strtonum.c -.PATH: ${LCRYPTO_SRC}/compat diff --git a/bin/pax/Makefile b/bin/pax/Makefile index b946929bd2..212536083b 100644 --- a/bin/pax/Makefile +++ b/bin/pax/Makefile @@ -5,7 +5,7 @@ SRCS= ar_io.c ar_subs.c buf_subs.c cache.c cpio.c file_subs.c ftree.c\ gen_subs.c getoldopt.c options.c pat_rep.c pax.c sel_subs.c tables.c\ tar.c tty_subs.c # compat -SRCS+= pwcache.c strtonum.c strmode.c dprintf.c +SRCS+= pwcache.c strmode.c dprintf.c # XXX for the time being, we need this to get the standard versions of # reentrant functions diff --git a/bin/pax/strtonum.c b/bin/pax/strtonum.c deleted file mode 100644 index fdfc72aa77..0000000000 --- a/bin/pax/strtonum.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ - -/* - * Copyright (c) 2004 Ted Unangst and Todd Miller - * All rights reserved. - * - * 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 - -#define INVALID 1 -#define TOOSMALL 2 -#define TOOLARGE 3 - -long long -strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) -{ - long long ll = 0; - int error = 0; - char *ep; - struct errval { - const char *errstr; - int err; - } ev[4] = { - { NULL, 0 }, - { "invalid", EINVAL }, - { "too small", ERANGE }, - { "too large", ERANGE }, - }; - - ev[0].err = errno; - errno = 0; - if (minval > maxval) { - error = INVALID; - } else { - ll = strtoll(numstr, &ep, 10); - if (numstr == ep || *ep != '\0') - error = INVALID; - else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) - error = TOOSMALL; - else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) - error = TOOLARGE; - } - if (errstrp != NULL) - *errstrp = ev[error].errstr; - errno = ev[error].err; - if (error) - ll = 0; - - return (ll); -} diff --git a/lib/libcrypto/compat/include/stdlib.h b/lib/libcrypto/compat/include/stdlib.h deleted file mode 100644 index 11f82bafc0..0000000000 --- a/lib/libcrypto/compat/include/stdlib.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * stdlib.h compatibility shim - * Public domain - */ - -#ifdef _MSC_VER -#if _MSC_VER >= 1900 -#include <../ucrt/stdlib.h> -#else -#include <../include/stdlib.h> -#endif -#else -#include_next -#endif - -#ifndef LIBCRYPTOCOMPAT_STDLIB_H -#define LIBCRYPTOCOMPAT_STDLIB_H - -#include -#include - -#ifndef HAVE_ARC4RANDOM_BUF -uint32_t arc4random(void); -void arc4random_buf(void *_buf, size_t n); -uint32_t arc4random_uniform(uint32_t upper_bound); -#endif - -#ifndef HAVE_REALLOCARRAY -void *reallocarray(void *, size_t, size_t); -#endif - -#ifndef HAVE_RECALLOCARRAY -void *recallocarray(void *, size_t, size_t, size_t); -#endif - -#ifndef HAVE_STRTONUM -long long strtonum(const char *nptr, long long minval, - long long maxval, const char **errstr); -#endif - -#endif diff --git a/lib/libcrypto/compat/strtonum.c b/lib/libcrypto/compat/strtonum.c deleted file mode 100644 index fdfc72aa77..0000000000 --- a/lib/libcrypto/compat/strtonum.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ - -/* - * Copyright (c) 2004 Ted Unangst and Todd Miller - * All rights reserved. - * - * 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 - -#define INVALID 1 -#define TOOSMALL 2 -#define TOOLARGE 3 - -long long -strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) -{ - long long ll = 0; - int error = 0; - char *ep; - struct errval { - const char *errstr; - int err; - } ev[4] = { - { NULL, 0 }, - { "invalid", EINVAL }, - { "too small", ERANGE }, - { "too large", ERANGE }, - }; - - ev[0].err = errno; - errno = 0; - if (minval > maxval) { - error = INVALID; - } else { - ll = strtoll(numstr, &ep, 10); - if (numstr == ep || *ep != '\0') - error = INVALID; - else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) - error = TOOSMALL; - else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) - error = TOOLARGE; - } - if (errstrp != NULL) - *errstrp = ev[error].errstr; - errno = ev[error].err; - if (error) - ll = 0; - - return (ll); -} -- 2.11.4.GIT