getenv.c 731 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef _GNU_SOURCE
  10. # define _GNU_SOURCE
  11. #endif
  12. #include <stdlib.h>
  13. #include "internal/cryptlib.h"
  14. char *ossl_safe_getenv(const char *name)
  15. {
  16. #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
  17. # if __GLIBC_PREREQ(2, 17)
  18. # define SECURE_GETENV
  19. return secure_getenv(name);
  20. # endif
  21. #endif
  22. #ifndef SECURE_GETENV
  23. if (OPENSSL_issetugid())
  24. return NULL;
  25. return getenv(name);
  26. #endif
  27. }