memzero.h: Move memzero() and strzero() to their own header

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-07-30 13:18:03 +02:00
committed by Iker Pedrosa
parent 093fb605f9
commit 6b11077f09
24 changed files with 57 additions and 14 deletions

View File

@@ -85,6 +85,7 @@ libshadow_la_SOURCES = \
mail.c \
mempcpy.c \
mempcpy.h \
memzero.h \
motd.c \
myname.c \
nss.c \

View File

@@ -23,6 +23,7 @@
#include <signal.h>
#include "alloc.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#ifdef WITH_TCB

View File

@@ -47,20 +47,6 @@
#include <sys/time.h>
#include <time.h>
#ifdef HAVE_MEMSET_EXPLICIT
# define memzero(ptr, size) memset_explicit((ptr), 0, (size))
#elif defined HAVE_EXPLICIT_BZERO /* !HAVE_MEMSET_S */
# define memzero(ptr, size) explicit_bzero((ptr), (size))
#else /* !HAVE_MEMSET_S && HAVE_EXPLICIT_BZERO */
static inline void memzero(void *ptr, size_t size)
{
ptr = memset(ptr, '\0', size);
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
}
#endif /* !HAVE_MEMSET_S && !HAVE_EXPLICIT_BZERO */
#define strzero(s) memzero(s, strlen(s)) /* warning: evaluates twice */
#include <dirent.h>
/*

View File

@@ -17,7 +17,10 @@
#include "defines.h"
#include "faillog.h"
#include "failure.h"
#include "memzero.h"
#include "prototypes.h"
#define YEAR (365L*DAY)
/*
* failure - make failure entry

View File

@@ -13,6 +13,7 @@
#ident "$Id$"
#include "alloc.h"
#include "memzero.h"
#include "prototypes.h"
#include "defines.h"
#include "groupio.h"

View File

@@ -29,6 +29,7 @@
#include "getdef.h"
#include "shadowlog.h"
#include <sys/resource.h>
#include "memzero.h"
#ifndef LIMITS_FILE
#define LIMITS_FILE "/etc/limits"
#endif

View File

@@ -17,6 +17,7 @@
#include <time.h>
#include "defines.h"
#include <lastlog.h>
#include "memzero.h"
#include "prototypes.h"
/*

View File

@@ -16,6 +16,7 @@
#include <signal.h>
#include "alloc.h"
#include "memzero.h"
#include "prototypes.h"
#include "defines.h"
#include "getdef.h"

33
lib/memzero.h Normal file
View File

@@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: 2022-2023, Christian Göttsche <cgzones@googlemail.com>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SHADOW_INCLUDE_LIBMISC_MEMZERO_H_
#define SHADOW_INCLUDE_LIBMISC_MEMZERO_H_
#include <config.h>
#include <stddef.h>
#include <string.h>
#include <strings.h>
#ifdef HAVE_MEMSET_EXPLICIT
# define memzero(ptr, size) memset_explicit((ptr), 0, (size))
#elif defined HAVE_EXPLICIT_BZERO /* !HAVE_MEMSET_S */
# define memzero(ptr, size) explicit_bzero((ptr), (size))
#else /* !HAVE_MEMSET_S && HAVE_EXPLICIT_BZERO */
static inline void memzero(void *ptr, size_t size)
{
ptr = memset(ptr, '\0', size);
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
}
#endif /* !HAVE_MEMSET_S && !HAVE_EXPLICIT_BZERO */
#define strzero(s) memzero(s, strlen(s)) /* warning: evaluates twice */
#endif // include guard

View File

@@ -21,6 +21,7 @@
#include <stdio.h>
#include "alloc.h"
#include "memzero.h"
#include "prototypes.h"
#include "defines.h"
#include "getdef.h"

View File

@@ -20,6 +20,7 @@
#include <unistd.h>
#include "prototypes.h"
#include "defines.h"
#include "memzero.h"
#include "pwauth.h"
#include "getdef.h"
#ifdef SKEY

View File

@@ -16,6 +16,7 @@
#include "alloc.h"
#include "defines.h"
#include "memzero.h"
#include "prototypes.h"
#include "pwio.h"

View File

@@ -19,6 +19,7 @@
#include "defines.h"
#include "commonio.h"
#include "getdef.h"
#include "memzero.h"
#include "sgroupio.h"
/*@null@*/ /*@only@*/struct sgrp *__sgr_dup (const struct sgrp *sgent)

View File

@@ -18,6 +18,7 @@
#include <stdio.h>
#include "alloc.h"
#include "memzero.h"
#include "shadowio.h"
/*@null@*/ /*@only@*/struct spwd *__spw_dup (const struct spwd *spent)

View File

@@ -29,6 +29,7 @@
#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "memzero.h"
#include "pwio.h"
#include "shadowio.h"
#include "shadowlog.h"

View File

@@ -20,6 +20,7 @@
#include <assert.h>
#include "defines.h"
#include "faillog.h"
#include "memzero.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"

View File

@@ -23,6 +23,7 @@
#include "alloc.h"
#include "defines.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"

View File

@@ -27,6 +27,7 @@
#include "defines.h"
#include "getdef.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"

View File

@@ -25,6 +25,7 @@
#include "defines.h"
#include "prototypes.h"
#include "getdef.h"
#include "memzero.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"

View File

@@ -30,6 +30,7 @@
#include "faillog.h"
#include "failure.h"
#include "getdef.h"
#include "memzero.h"
#include "prototypes.h"
#include "pwauth.h"
/*@-exitarg@*/

View File

@@ -23,6 +23,7 @@
#include "alloc.h"
#include "defines.h"
#include "getdef.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"

View File

@@ -18,6 +18,7 @@
#include <sys/ioctl.h>
#include "defines.h"
#include "getdef.h"
#include "memzero.h"
#include "prototypes.h"
#include "pwauth.h"
/*@-exitarg@*/

View File

@@ -42,6 +42,7 @@
#include "faillog.h"
#include "getdef.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"

View File

@@ -37,6 +37,7 @@
#include "faillog.h"
#include "getdef.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"