tst-empty-env.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Test that passing a NULL value does not hang environment traversal in
  2. tunables.
  3. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. /* The test is useful only when the source is configured with
  17. --enable-hardcoded-path-in-tests since otherwise the execve just picks up
  18. the system dynamic linker. */
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include <errno.h>
  23. static int
  24. do_test (int argc, char **argv)
  25. {
  26. if (argc == 2)
  27. return 0;
  28. char envname[] = "FOOBAR";
  29. char *filename = program_invocation_name;
  30. char *newargv[] = {filename, filename, NULL};
  31. char *newenviron[] = {envname, NULL};
  32. /* This was reported in Fedora:
  33. https://bugzilla.redhat.com/show_bug.cgi?id=1414589
  34. If one of the environment variables has no value, then the environment
  35. traversal must skip and also advance to the next environment entry. The
  36. bug in question would cause this test to hang in an infinite loop. */
  37. int ret = execve (filename, newargv, newenviron);
  38. if (ret != 0)
  39. printf ("execve failed: %m");
  40. /* We will reach here only if we fail execve. */
  41. return 1;
  42. }
  43. #define TEST_FUNCTION_ARGV do_test
  44. #include <support/test-driver.c>