From 1bdead1bb4cd6a4eb9f8ac8631728df9b1427c95 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 11 Feb 2025 09:08:04 -0700 Subject: [PATCH] Only use system includes for mksiglist and mksigname. These are standalone programs that run on the host system (which may differ from the target system) so we should not include config.h and sudo_compat.h. --- lib/util/Makefile.in | 12 ++++-------- lib/util/mksiglist.c | 18 ++++++++++++------ lib/util/mksigname.c | 17 ++++++++++++----- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/util/Makefile.in b/lib/util/Makefile.in index b36266940..428a1277d 100644 --- a/lib/util/Makefile.in +++ b/lib/util/Makefile.in @@ -1148,19 +1148,15 @@ mkdirat.i: $(srcdir)/mkdirat.c $(incdir)/sudo_compat.h $(top_builddir)/config.h $(CPP) $(CPPFLAGS) $(srcdir)/mkdirat.c > $@ mkdirat.plog: mkdirat.i rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/mkdirat.c --i-file mkdirat.i --output-file $@ -mksiglist.lo: $(srcdir)/mksiglist.c $(incdir)/sudo_compat.h \ - $(srcdir)/mksiglist.h $(top_builddir)/config.h +mksiglist.lo: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(HARDENING_CFLAGS) $(srcdir)/mksiglist.c -mksiglist.i: $(srcdir)/mksiglist.c $(incdir)/sudo_compat.h \ - $(srcdir)/mksiglist.h $(top_builddir)/config.h +mksiglist.i: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(CPP) $(CPPFLAGS) $(srcdir)/mksiglist.c > $@ mksiglist.plog: mksiglist.i rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/mksiglist.c --i-file mksiglist.i --output-file $@ -mksigname.lo: $(srcdir)/mksigname.c $(incdir)/sudo_compat.h \ - $(srcdir)/mksigname.h $(top_builddir)/config.h +mksigname.lo: $(srcdir)/mksigname.c $(srcdir)/mksigname.h $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(HARDENING_CFLAGS) $(srcdir)/mksigname.c -mksigname.i: $(srcdir)/mksigname.c $(incdir)/sudo_compat.h \ - $(srcdir)/mksigname.h $(top_builddir)/config.h +mksigname.i: $(srcdir)/mksigname.c $(srcdir)/mksigname.h $(CPP) $(CPPFLAGS) $(srcdir)/mksigname.c > $@ mksigname.plog: mksigname.i rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/mksigname.c --i-file mksigname.i --output-file $@ diff --git a/lib/util/mksiglist.c b/lib/util/mksiglist.c index 6495e22e0..cf9790875 100644 --- a/lib/util/mksiglist.c +++ b/lib/util/mksiglist.c @@ -21,15 +21,21 @@ * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com */ +/* + * Self-contained program run on the host to generate sudo_sys_siglist[] + * for systems that lack sys_siglist[] or the equivalent (like HP-UX). + * + * We cannot include config.h or sudo_compat.h here since those refer + * to the target, not the host, system. + */ -#include - +#include #include #include -#include - -sudo_dso_public int main(int argc, char *argv[]); +#ifndef nitems +# define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) +#endif int main(int argc, char *argv[]) @@ -44,7 +50,7 @@ main(int argc, char *argv[]) * so it cannot use any of the functions in libsudo_util. */ puts("const char *const sudo_sys_siglist[] = {"); - for (i = 0; i < NSIG; i++) { + for (i = 0; i < nitems(sudo_sys_siglist); i++) { if (sudo_sys_siglist[i] != NULL) { printf(" \"%s\",\n", sudo_sys_siglist[i]); } else { diff --git a/lib/util/mksigname.c b/lib/util/mksigname.c index 1b51199c2..ebad8285c 100644 --- a/lib/util/mksigname.c +++ b/lib/util/mksigname.c @@ -22,14 +22,21 @@ */ -#include +/* + * Self-contained program run on the host to generate sudo_sys_signame[] + * for systems that lack sys_signame[] or the equivalent (like HP-UX). + * + * We cannot include config.h or sudo_compat.h here since those refer + * to the target, not the host, system. + */ +#include #include #include -#include - -sudo_dso_public int main(int argc, char *argv[]); +#ifndef nitems +# define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) +#endif int main(int argc, char *argv[]) @@ -44,7 +51,7 @@ main(int argc, char *argv[]) * so it cannot use any of the functions in libsudo_util. */ puts("const char *const sudo_sys_signame[] = {"); - for (i = 0; i < NSIG; i++) { + for (i = 0; i < nitems(sudo_sys_signame); i++) { if (sudo_sys_signame[i] != NULL) { printf(" \"%s\",\n", sudo_sys_signame[i]); } else {