From 0e0a310acf5111251589116343897a63ebc88e7a Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Thu, 10 Aug 2023 09:45:32 +0200 Subject: [PATCH] libmisc: add freezero source code If shadow is built without libbsd support, then freezero() needs to be provided from the project. Signed-off-by: Iker Pedrosa --- libmisc/Makefile.am | 2 ++ libmisc/freezero.c | 30 ++++++++++++++++++++++++++++++ libmisc/freezero.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 libmisc/freezero.c create mode 100644 libmisc/freezero.h diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am index 1540f3c44..10bf1537f 100644 --- a/libmisc/Makefile.am +++ b/libmisc/Makefile.am @@ -107,6 +107,8 @@ endif if !WITH_LIBBSD libmisc_la_SOURCES += \ + freezero.h \ + freezero.c \ readpassphrase.h \ readpassphrase.c endif diff --git a/libmisc/freezero.c b/libmisc/freezero.c new file mode 100644 index 000000000..c565f4351 --- /dev/null +++ b/libmisc/freezero.c @@ -0,0 +1,30 @@ +/* $OpenBSD: malloc.c,v 1.267 2020/11/23 15:42:11 otto Exp $ */ +/* + * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek + * + * 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 + +void +freezero(void *ptr, size_t sz) +{ + /* This is legal. */ + if (ptr == NULL) + return; + + explicit_bzero(ptr, sz); + free(ptr); +} diff --git a/libmisc/freezero.h b/libmisc/freezero.h new file mode 100644 index 000000000..8dbcd7c42 --- /dev/null +++ b/libmisc/freezero.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2005 Aurelien Jarno + * Copyright © 2006 Robert Millan + * Copyright © 2008-2011 Guillem Jover + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBBSD_FREEZERO_H +#define LIBBSD_FREEZERO_H + +void freezero(void *ptr, size_t size); + +#endif -- 2.47.2