Skip to content

Commit 18dcbad

Browse files
committed
Make temporary directory safely when ~/.w3m is unwritable
1 parent b592dac commit 18dcbad

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

Diff for: config.h.dist

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ typedef long clen_t;
210210
#define HAVE_SRANDOM
211211
#undef HAVE_GETPASSPHRASE
212212
#define HAVE_CHDIR
213+
#define HAVE_MKDTEMP
213214

214215

215216
#define SETJMP(env) sigsetjmp(env,1)

Diff for: config.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ typedef long clen_t;
143143
#undef HAVE_SRANDOM
144144
#undef HAVE_GETPASSPHRASE
145145
#undef HAVE_CHDIR
146+
#undef HAVE_MKDTEMP
146147
#undef HAVE_SETPGRP
147148
#undef HAVE_SETLOCALE
148149
#undef HAVE_LANGINFO_CODESET

Diff for: configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -8767,7 +8767,7 @@ _ACEOF
87678767

87688768

87698769

8770-
for ac_func in strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale
8770+
for ac_func in strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir mkdtemp getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale
87718771
do :
87728772
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
87738773
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

Diff for: configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ dnl AC_FUNC_MEMCMP
150150
dnl AC_FUNC_MMAP
151151
dnl AC_FUNC_SETVBUF_REVERSED
152152
dnl AC_FUNC_VPRINTF
153-
AC_CHECK_FUNCS(strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale)
153+
AC_CHECK_FUNCS(strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir mkdtemp getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale)
154154
AC_FUNC_STRFTIME
155155
AC_FUNC_WAIT3
156156
AC_FUNC_SETPGRP

Diff for: main.c

+7
Original file line numberDiff line numberDiff line change
@@ -5971,6 +5971,13 @@ w3m_exit(int i)
59715971
#endif
59725972
#ifdef __MINGW32_VERSION
59735973
WSACleanup();
5974+
#endif
5975+
#ifdef HAVE_MKDTEMP
5976+
if (no_rc_dir && tmp_dir != rc_dir)
5977+
if (rmdir(tmp_dir) != 0) {
5978+
fprintf(stderr, "Can't remove temporary directory (%s)!\n", tmp_dir);
5979+
exit(1);
5980+
}
59745981
#endif
59755982
exit(i);
59765983
}

Diff for: rc.c

+5
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,11 @@ init_rc(void)
13301330
((tmp_dir = getenv("TMP")) == NULL || *tmp_dir == '\0') &&
13311331
((tmp_dir = getenv("TEMP")) == NULL || *tmp_dir == '\0'))
13321332
tmp_dir = "/tmp";
1333+
#ifdef HAVE_MKDTEMP
1334+
tmp_dir = mkdtemp(Strnew_m_charp(tmp_dir, "/w3m-XXXXXX", NULL)->ptr);
1335+
if (tmp_dir == NULL)
1336+
tmp_dir = rc_dir;
1337+
#endif
13331338
create_option_search_table();
13341339
goto open_rc;
13351340
}

0 commit comments

Comments
 (0)