age.c \
agetpass.c \
agetpass.h \
- alloc.c \
- alloc.h \
+ alloc/calloc.c \
+ alloc/calloc.h \
+ alloc/malloc.c \
+ alloc/malloc.h \
+ alloc/realloc.c \
+ alloc/realloc.h \
+ alloc/reallocf.c \
+ alloc/reallocf.h \
+ alloc/x/xcalloc.c \
+ alloc/x/xcalloc.h \
+ alloc/x/xmalloc.c \
+ alloc/x/xmalloc.h \
+ alloc/x/xrealloc.c \
+ alloc/x/xrealloc.h \
atoi/a2i.c \
atoi/a2i.h \
atoi/getnum.c \
#include <grp.h>
#include <errno.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/reallocf.h"
#include "shadowlog.h"
#ident "$Id$"
#ident "$Id$"
-#include "alloc.h"
+#include "alloc/malloc.h"
#if WITH_LIBBSD == 0
#include "freezero.h"
+++ /dev/null
-// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
-// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
-// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
-// SPDX-FileCopyrightText: 2008 , Nicolas François
-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
-// SPDX-License-Identifier: BSD-3-Clause
-
-/* Replacements for malloc and strdup with error checking. Too trivial
- to be worth copyrighting :-). I did that because a lot of code used
- malloc and strdup without checking for NULL pointer, and I like some
- message better than a core dump... --marekm
-
- Yeh, but. Remember that bailing out might leave the system in some
- bizarre state. You really want to put in error checking, then add
- some back-out failure recovery code. -- jfh */
-
-#include <config.h>
-
-#include "alloc.h"
-
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-
-#include "defines.h"
-#include "prototypes.h"
-#include "shadowlog.h"
-
-
-extern inline void *xmallocarray(size_t nmemb, size_t size);
-extern inline void *mallocarray(size_t nmemb, size_t size);
-extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
-
-
-void *
-xcalloc(size_t nmemb, size_t size)
-{
- void *p;
-
- p = calloc(nmemb, size);
- if (p == NULL)
- goto x;
-
- return p;
-
-x:
- fprintf(log_get_logfd(), _("%s: %s\n"),
- log_get_progname(), strerror(errno));
- exit(13);
-}
-
-
-void *
-xreallocarray(void *p, size_t nmemb, size_t size)
-{
- p = reallocarrayf(p, nmemb, size);
- if (p == NULL)
- goto x;
-
- return p;
-
-x:
- fprintf(log_get_logfd(), _("%s: %s\n"),
- log_get_progname(), strerror(errno));
- exit(13);
-}
+++ /dev/null
-// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
-// SPDX-License-Identifier: BSD-3-Clause
-
-
-#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
-#define SHADOW_INCLUDE_LIB_MALLOC_H_
-
-
-#include <config.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#include "attr.h"
-
-
-#define CALLOC(n, type) ((type *) calloc(n, sizeof(type)))
-#define XCALLOC(n, type) ((type *) xcalloc(n, sizeof(type)))
-#define MALLOC(n, type) ((type *) mallocarray(n, sizeof(type)))
-#define XMALLOC(n, type) ((type *) xmallocarray(n, sizeof(type)))
-
-#define REALLOC(ptr, n, type) \
-( \
- _Generic(ptr, type *: (type *) reallocarray(ptr, n, sizeof(type))) \
-)
-
-#define REALLOCF(ptr, n, type) \
-( \
- _Generic(ptr, type *: (type *) reallocarrayf(ptr, n, sizeof(type))) \
-)
-
-#define XREALLOC(ptr, n, type) \
-( \
- _Generic(ptr, type *: (type *) xreallocarray(ptr, n, sizeof(type))) \
-)
-
-
-ATTR_MALLOC(free)
-inline void *xmallocarray(size_t nmemb, size_t size);
-ATTR_MALLOC(free)
-inline void *mallocarray(size_t nmemb, size_t size);
-ATTR_MALLOC(free)
-inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
-
-ATTR_MALLOC(free)
-void *xcalloc(size_t nmemb, size_t size);
-ATTR_MALLOC(free)
-void *xreallocarray(void *p, size_t nmemb, size_t size);
-
-
-inline void *
-xmallocarray(size_t nmemb, size_t size)
-{
- return xreallocarray(NULL, nmemb, size);
-}
-
-
-inline void *
-mallocarray(size_t nmemb, size_t size)
-{
- return reallocarray(NULL, nmemb, size);
-}
-
-
-inline void *
-reallocarrayf(void *p, size_t nmemb, size_t size)
-{
- void *q;
-
- q = reallocarray(p, nmemb, size);
-
- /* realloc(p, 0) is equivalent to free(p); avoid double free. */
- if (q == NULL && nmemb != 0 && size != 0)
- free(p);
- return q;
-}
-
-
-#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/calloc.h"
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
+
+
+#include <config.h>
+
+#include <stdlib.h>
+
+
+#define CALLOC(n, type) ((type *) calloc(n, sizeof(type)))
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/malloc.h"
+
+#include <stddef.h>
+
+
+extern inline void *mallocarray(size_t nmemb, size_t size);
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
+
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include "attr.h"
+
+
+#define MALLOC(n, type) ((type *) mallocarray(n, sizeof(type)))
+
+
+ATTR_MALLOC(free)
+inline void *mallocarray(size_t nmemb, size_t size);
+
+
+inline void *
+mallocarray(size_t nmemb, size_t size)
+{
+ return reallocarray(NULL, nmemb, size);
+}
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/realloc.h"
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
+
+
+#include <config.h>
+
+#include <stdlib.h>
+
+
+#define REALLOC(ptr, n, type) \
+( \
+ _Generic(ptr, type *: (type *) reallocarray(ptr, n, sizeof(type))) \
+)
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/reallocf.h"
+
+#include <stddef.h>
+
+
+extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
+
+
+#include <config.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "attr.h"
+
+
+#define REALLOCF(ptr, n, type) \
+( \
+ _Generic(ptr, type *: (type *) reallocarrayf(ptr, n, sizeof(type))) \
+)
+
+
+ATTR_MALLOC(free)
+inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
+
+
+inline void *
+reallocarrayf(void *p, size_t nmemb, size_t size)
+{
+ void *q;
+
+ q = reallocarray(p, nmemb, size);
+
+ /* realloc(p, 0) is equivalent to free(p); avoid double free. */
+ if (q == NULL && nmemb != 0 && size != 0)
+ free(p);
+ return q;
+}
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/x/xcalloc.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "defines.h"
+#include "shadowlog.h"
+
+
+void *
+xcalloc(size_t nmemb, size_t size)
+{
+ void *p;
+
+ p = calloc(nmemb, size);
+ if (p == NULL)
+ goto x;
+
+ return p;
+
+x:
+ fprintf(log_get_logfd(), _("%s: %s\n"),
+ log_get_progname(), strerror(errno));
+ exit(13);
+}
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
+
+
+#include <config.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "attr.h"
+
+
+#define XCALLOC(n, type) ((type *) xcalloc(n, sizeof(type)))
+
+
+ATTR_MALLOC(free)
+void *xcalloc(size_t nmemb, size_t size);
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/x/xmalloc.h"
+
+#include <stddef.h>
+
+
+extern inline void *xmallocarray(size_t nmemb, size_t size);
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
+#define SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
+
+
+#include <config.h>
+
+#include <stddef.h>
+
+#include "alloc/x/xrealloc.h"
+#include "attr.h"
+
+
+#define XMALLOC(n, type) ((type *) xmallocarray(n, sizeof(type)))
+
+
+ATTR_MALLOC(free)
+inline void *xmallocarray(size_t nmemb, size_t size);
+
+
+inline void *
+xmallocarray(size_t nmemb, size_t size)
+{
+ return xreallocarray(NULL, nmemb, size);
+}
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
+// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
+// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
+// SPDX-FileCopyrightText: 2008 , Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "alloc/x/xrealloc.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "alloc/reallocf.h"
+#include "defines.h"
+#include "shadowlog.h"
+
+
+void *
+xreallocarray(void *p, size_t nmemb, size_t size)
+{
+ p = reallocarrayf(p, nmemb, size);
+ if (p == NULL)
+ goto x;
+
+ return p;
+
+x:
+ fprintf(log_get_logfd(), _("%s: %s\n"),
+ log_get_progname(), strerror(errno));
+ exit(13);
+}
--- /dev/null
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
+#define SHADOW_INCLUDE_LIB_MALLOC_H_
+
+
+#include <config.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "attr.h"
+
+
+#define XREALLOC(ptr, n, type) \
+( \
+ _Generic(ptr, type *: (type *) xreallocarray(ptr, n, sizeof(type))) \
+)
+
+
+ATTR_MALLOC(free)
+void *xreallocarray(void *p, size_t nmemb, size_t size);
+
+
+#endif // include guard
#include <stdlib.h>
#include <utime.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/reallocf.h"
#include "atoi/getnum.h"
#include "commonio.h"
#include "defines.h"
#include <fcntl.h>
#include <stdio.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "prototypes.h"
#include "defines.h"
#include <stdlib.h>
#include <string.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
+#include "alloc/x/xrealloc.h"
#include "prototypes.h"
#include "defines.h"
#include "shadowlog.h"
#include <stdio.h>
#include <errno.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
#include "prototypes.h"
#include "groupio.h"
#include "getdef.h"
#include <stdio.h>
#include <errno.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
#include "prototypes.h"
#include "pwio.h"
#include "getdef.h"
#include <libeconf.h>
#endif
-#include "alloc.h"
#include "atoi/str2i.h"
#include "defines.h"
#include "getdef.h"
#include <assert.h>
#include <stdio.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
+#include "alloc/malloc.h"
#include "prototypes.h"
#include "defines.h"
#include "commonio.h"
#ident "$Id$"
-#include "alloc.h"
+#include "alloc/calloc.h"
+#include "alloc/malloc.h"
#include "memzero.h"
#include "prototypes.h"
#include "defines.h"
#include <stdio.h>
#include <string.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/realloc.h"
#include "prototypes.h"
#include "defines.h"
#include <stdio.h>
#include <strings.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
+#include "alloc/x/xmalloc.h"
#include "atoi/str2i.h"
#include "prototypes.h"
#include "string/sprintf/stpeprintf.h"
#include <assert.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "prototypes.h"
#include "defines.h"
#include "string/strdup/xstrdup.h"
#include <stdio.h>
#include <signal.h>
-#include "alloc.h"
#include "attr.h"
#include "memzero.h"
#include "prototypes.h"
#include <stdio.h>
#include <string.h>
-#include "alloc.h"
#include "getdef.h"
#include "string/sprintf/xasprintf.h"
#include <ctype.h>
#include <stdatomic.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
#include "prototypes.h"
#include "../libsubid/subid.h"
#include "shadowlog_internal.h"
#include <security/pam_appl.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
#include "attr.h"
#include "memzero.h"
#include "prototypes.h"
#include "atoi/getnum.h"
#include "defines.h"
-#include "alloc.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include <stdio.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
#include "defines.h"
#include "memzero.h"
#include "prototypes.h"
#include <unistd.h>
#include <lib/prototypes.h>
-#include "alloc.h"
#include "run_part.h"
#include "shadowlog_internal.h"
#include <grp.h>
#include <string.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/reallocf.h"
#include "atoi/getnum.h"
#include "defines.h"
#include "prototypes.h"
#ident "$Id$"
-#include "alloc.h"
+#include "alloc/calloc.h"
+#include "alloc/malloc.h"
#include "prototypes.h"
#include "defines.h"
#include "commonio.h"
#include <shadow.h>
#include <stdio.h>
-#include "alloc.h"
+#include "alloc/calloc.h"
#include "memzero.h"
#include "shadowio.h"
#include <sys/wait.h>
#include <sys/types.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
#include "exitcodes.h"
#include "defines.h"
#include "prototypes.h"
#include <string.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "attr.h"
#include <string.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "sizeof.h"
#include "string/strcpy/strncat.h"
#include <fcntl.h>
#include <string.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/realloc.h"
+#include "alloc/reallocf.h"
#include "atoi/str2i.h"
#include "string/sprintf/snprintf.h"
#include <stdio.h>
#include <fcntl.h>
-#include "alloc.h"
+#include "alloc/x/xcalloc.h"
+#include "alloc/x/xmalloc.h"
#include "sizeof.h"
#include "string/strcpy/strncpy.h"
#include "string/strcpy/strtcpy.h"
#include <stdio.h>
#include <errno.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/x/xrealloc.h"
#include "prototypes.h"
#include "shadowlog.h"
#include <sys/types.h>
#include "agetpass.h"
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "defines.h"
#include "groupio.h"
#endif /* USE_PAM */
#include <pwd.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "defines.h"
#include "prototypes.h"
#include "groupio.h"
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include <pwd.h>
#include <stdio.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "defines.h"
#include "prototypes.h"
#include "shadowlog.h"
#include <stdio.h>
#include <sys/types.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
#include "defines.h"
/* local function prototypes */
#include <sys/ioctl.h>
#include <assert.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "chkname.h"
#include "defines.h"
#include <assert.h>
#include "agetpass.h"
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
#include <errno.h>
#include <string.h>
-#include "alloc.h"
+#include "alloc/reallocf.h"
#include "atoi/getnum.h"
#include "atoi/str2i.h"
#ifdef ACCT_TOOLS_SETUID
#include <fcntl.h>
#endif /* !USE_PAM */
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "cast.h"
#include "prototypes.h"
#include <time.h>
#include <unistd.h>
-#include "alloc.h"
+#include "alloc/x/xmalloc.h"
#include "atoi/str2i.h"
#include "atoi/getnum.h"
#include "chkname.h"
#include <sys/types.h>
#include <time.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
+#include "alloc/x/xmalloc.h"
#include "atoi/a2i.h"
#include "atoi/getnum.h"
#include "atoi/str2i.h"
#include <unistd.h>
#include <utime.h>
-#include "alloc.h"
#include "defines.h"
#include "getdef.h"
#include "groupio.h"
#include <stdbool.h>
#include <subid.h>
#include <string.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
enum subid_status shadow_subid_has_any_range(const char *owner, enum subid_type t, bool *result)
{
#include <stdint.h> // Required by <cmocka.h>
#include <cmocka.h>
-#include "alloc.h"
+#include "alloc/malloc.h"
#include "chkname.h"