]> granicus.if.org Git - sudo/commitdiff
Add test for getprogname() and symbolic links; bug 654
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 25 Jul 2014 15:37:58 +0000 (09:37 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 25 Jul 2014 15:37:58 +0000 (09:37 -0600)
MANIFEST
lib/util/Makefile.in
lib/util/regress/progname/progname_test.c [new file with mode: 0644]

index c4749baa20bbf945c9c1c619756be573e8f466e5..a0814248d69b9042582d013fc06ff3e4c398eda4 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -115,6 +115,7 @@ lib/util/regress/fnmatch/fnm_test.in
 lib/util/regress/glob/files
 lib/util/regress/glob/globtest.c
 lib/util/regress/glob/globtest.in
+lib/util/regress/progname/progname_test.c
 lib/util/regress/sudo_conf/conf_test.c
 lib/util/regress/sudo_conf/test1.in
 lib/util/regress/sudo_conf/test1.out.ok
index f22082e6fd61dcbe9dbc4c7e74f8ec46bd7eb38e..8e7a211bddfd088a3817284321649d78910e1c41 100644 (file)
@@ -77,7 +77,7 @@ SHLIB_VERSION = 0:0:0
 CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
 
 # Regression tests
-TEST_PROGS = atofoo_test conf_test hltq_test parseln_test @COMPAT_TEST_PROGS@
+TEST_PROGS = atofoo_test conf_test hltq_test parseln_test progname_test @COMPAT_TEST_PROGS@
 TEST_LIBS = @LIBS@ @LIBINTL@
 TEST_LDFLAGS = @LDFLAGS@
 
@@ -104,6 +104,8 @@ ATOFOO_TEST_OBJS = atofoo_test.lo locale_stub.lo
 
 PARSELN_TEST_OBJS = parseln_test.lo locale_stub.lo
 
+PROGNAME_TEST_OBJS = progname_test.lo locale_stub.lo
+
 CONF_TEST_OBJS = conf_test.lo locale_stub.lo
 
 HLTQ_TEST_OBJS = hltq_test.lo locale_stub.lo
@@ -157,22 +159,25 @@ $(srcdir)/mksigname.h: $(srcdir)/siglist.in
        fi
 
 atofoo_test: $(ATOFOO_TEST_OBJS) libsudo_util.la
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(ATOFOO_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -no-fast-install
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(ATOFOO_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
 
 conf_test: $(CONF_TEST_OBJS) libsudo_util.la
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(CONF_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -no-fast-install
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(CONF_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
 
 fnm_test: $(FNM_TEST_OBJS) libsudo_util.la
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(FNM_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -no-fast-install
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(FNM_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
 
 globtest: $(GLOBTEST_OBJS) libsudo_util.la
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(GLOBTEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -no-fast-install
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(GLOBTEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
 
 hltq_test: $(HLTQ_TEST_OBJS) libsudo_util.la
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(HLTQ_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -no-fast-install
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(HLTQ_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
 
 parseln_test: $(PARSELN_TEST_OBJS) libsudo_util.la
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(PARSELN_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -no-fast-install
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(PARSELN_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS)
+
+progname_test: $(PROGNAME_TEST_OBJS) libsudo_util.la
+       $(LIBTOOL) --mode=link $(CC) -o $@ $(PROGNAME_TEST_OBJS) libsudo_util.la $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(TEST_LDFLAGS) $(TEST_LIBS) -static-libtool-libs
 
 pre-install:
 
@@ -216,6 +221,10 @@ check: $(TEST_PROGS)
            fi; \
            ./atofoo_test || rval=`expr $$rval + $$?`; \
            ./hltq_test || rval=`expr $$rval + $$?`; \
+           ./progname_test || rval=`expr $$rval + $$?`; \
+           rm -f ./progname_test2; ln -s ./progname_test ./progname_test2; \
+           ./progname_test2 || rval=`expr $$rval + $$?`; \
+           rm -f ./progname_test2; \
            build_dir=`pwd`; \
            cd $(srcdir); \
            for dir in sudo_conf sudo_parseln; do \
@@ -411,6 +420,10 @@ progname.lo: $(srcdir)/progname.c $(incdir)/compat/stdbool.h \
              $(incdir)/sudo_compat.h $(incdir)/sudo_util.h \
              $(top_builddir)/config.h
        $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/progname.c
+progname_test.lo: $(srcdir)/regress/progname/progname_test.c \
+                  $(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
+                  $(incdir)/sudo_util.h $(top_builddir)/config.h
+       $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/progname/progname_test.c
 pw_dup.lo: $(srcdir)/pw_dup.c $(incdir)/sudo_compat.h $(top_builddir)/config.h
        $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/pw_dup.c
 secure_path.lo: $(srcdir)/secure_path.c $(incdir)/compat/stdbool.h \
diff --git a/lib/util/regress/progname/progname_test.c b/lib/util/regress/progname/progname_test.c
new file mode 100644 (file)
index 0000000..6045fb3
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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 <config.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif /* STDC_HEADERS */
+#ifdef HAVE_STRING_H
+# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# include "compat/stdbool.h"
+#endif
+
+#include "sudo_compat.h"
+#include "sudo_util.h"
+
+__dso_public int main(int argc, char *argv[]);
+
+/*
+ * Test that getprogname() returns the expected result.
+ * On some systems (AIX), we may have issues with symbolic links.
+ */
+
+int
+main(int argc, char *argv[])
+{
+    char *progbase = "progname_test";
+
+    if (argc > 0) {
+       if ((progbase = strrchr(argv[0], '/')) != NULL)
+           progbase++;
+       else
+           progbase = argv[0];
+    }
+    initprogname(progbase);
+
+    /* Make sure getprogname() matches basename of argv[0]. */
+    if (strcmp(getprogname(), progbase) != 0) {
+       printf("%s: FAIL: incorrect program name \"%s\"\n",
+           progbase, getprogname());
+       exit(1);
+    }
+
+    exit(0);
+}