#include <sys/utsname.h>
#include <errno.h>
#include <sys/wait.h>
+#include <sys/time.h>
#define CHECK_PAGER \
if ((CurrentMenu == MENU_PAGER) && (idx >= 0) && \
return 0;
}
+static void mutt_srandom (void)
+{
+ struct timeval tv;
+ unsigned seed;
+
+ gettimeofday(&tv, NULL);
+ /* POSIX.1-2008 states that seed is 'unsigned' without specifying its width.
+ * Use as many of the lower order bits from the current time of day as the seed.
+ * If the upper bound is truncated, that is fine.
+ */
+ seed = (tv.tv_sec << 20) | tv.tv_usec;
+ srandom(seed);
+}
+
void mutt_init (int skip_sys_rc, LIST *commands)
{
struct passwd *pw;
ReverseAlias = hash_create (1031, 1);
mutt_menu_init ();
+ mutt_srandom ();
/*
* XXX - use something even more difficult to predict?
void _mutt_mktemp (char *s, size_t slen, const char *src, int line)
{
- snprintf (s, slen, "%s/mutt-%s-%d-%d-%d", NONULL (Tempdir), NONULL(Hostname), (int) getuid(), (int) getpid (), Counter++);
+ size_t n = snprintf (s, slen, "%s/mutt-%s-%d-%d-%ld%ld", NONULL(Tempdir), NONULL(Hostname),
+ (int) getuid(), (int) getpid(), random(), random());
+ if (n >= slen)
+ dprint(1, (debugfile, "%s:%d: ERROR: insufficient buffer space to hold temporary filename! slen=%zu but need %zu\n",
+ src, line, slen, n));
dprint (3, (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
- unlink (s);
+ if (unlink (s))
+ dprint(1, (debugfile, "%s:%d: ERROR: unable to unlink temporary file\n", src, line));
}
void mutt_free_alias (ALIAS **p)