SHA256
1
0
forked from pool/file
file/file-secure_getenv.patch

85 lines
2.7 KiB
Diff

---
file-5.38/configure.ac | 2 ++
file-5.38/src/file.c | 2 +-
file-5.38/src/file.h | 8 ++++++++
file-5.38/src/magic.c | 10 +++++-----
4 files changed, 16 insertions(+), 6 deletions(-)
--- file-5.38/configure.ac
+++ file-5.38/configure.ac 2019-12-17 09:29:37.751077718 +0000
@@ -115,6 +115,8 @@ if test "$enable_xzlib" != "no"; then
fi
AC_CHECK_TYPE([sig_t],[AC_DEFINE([HAVE_SIG_T],1,[Have sig_t type])],,[#include <signal.h>])
+AC_CHECK_FUNCS([__secure_getenv secure_getenv])
+
dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
--- file-5.38/src/file.c
+++ file-5.38/src/file.c 2019-12-17 09:23:55.973524728 +0000
@@ -647,7 +647,7 @@ docprint(const char *opts, int def)
private void
help(void)
{
- const unsigned long posix = (unsigned long)getenv("POSIXLY_CORRECT");
+ const unsigned long posix = (unsigned long)secure_getenv("POSIXLY_CORRECT");
(void)fputs(
"Usage: file [OPTION...] [FILE...]\n"
"Determine type of FILEs.\n"
--- file-5.38/src/file.h
+++ file-5.38/src/file.h 2019-12-17 09:23:55.977524652 +0000
@@ -650,4 +650,12 @@ static const char *rcsid(const char *p)
#define __RCSID(a)
#endif
+#ifndef HAVE_SECURE_GETENV
+# ifdef HAVE___SECURE_GETENV
+# define secure_getenv __secure_getenv
+# else
+# error neither secure_getenv nor __secure_getenv is available
+# endif
+#endif
+
#endif /* __file_h__ */
--- file-5.38/src/magic.c
+++ file-5.38/src/magic.c 2019-12-17 09:23:55.977524652 +0000
@@ -183,7 +183,7 @@ get_default_magic(void)
free(default_magic);
default_magic = NULL;
}
- if ((home = getenv("HOME")) == NULL)
+ if ((home = secure_getenv("HOME")) == NULL)
return MAGIC;
if (asprintf(&hmagicpath, "%s/.magic.mgc", home) < 0)
@@ -220,16 +220,16 @@ out:
}
/* First, try to get a magic file from user-application data */
- if ((home = getenv("LOCALAPPDATA")) != NULL)
+ if ((home = secure_getenv("LOCALAPPDATA")) != NULL)
_w32_append_path(&hmagicpath, "%s%s", home, hmagic);
/* Second, try to get a magic file from the user profile data */
- if ((home = getenv("USERPROFILE")) != NULL)
+ if ((home = secure_getenv("USERPROFILE")) != NULL)
_w32_append_path(&hmagicpath,
"%s/Local Settings/Application Data%s", home, hmagic);
/* Third, try to get a magic file from Common Files */
- if ((home = getenv("COMMONPROGRAMFILES")) != NULL)
+ if ((home = secure_getenv("COMMONPROGRAMFILES")) != NULL)
_w32_append_path(&hmagicpath, "%s%s", home, hmagic);
/* Fourth, try to get magic file relative to exe location */
@@ -250,7 +250,7 @@ magic_getpath(const char *magicfile, int
if (magicfile != NULL)
return magicfile;
- magicfile = getenv("MAGIC");
+ magicfile = secure_getenv("MAGIC");
if (magicfile != NULL)
return magicfile;