}
read_random_seed(func);
+ /* Update the seed immediately, in case another instance uses it. */
+ random_save_seed();
gsps = NULL;
mod = GetModuleHandle("KERNEL32");
if (random_active) {
random_get_savedata(&data, &len);
write_random_seed(data, len);
+ sfree(data);
}
}
void random_get_savedata(void **data, int *len)
{
+ void *buf = smalloc(POOLSIZE / 2);
random_stir();
- *data = pool.pool + pool.poolpos;
+ memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
*len = POOLSIZE / 2;
+ *data = buf;
+ random_stir();
}
pclose(fp);
read_random_seed(func);
+ random_save_seed();
}
void random_save_seed(void)
if (random_active) {
random_get_savedata(&data, &len);
write_random_seed(data, len);
+ sfree(data);
}
}
char fname[FILENAME_MAX];
make_filename(fname, INDEX_RANDSEED);
- fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0600);
+ /*
+ * Don't truncate the random seed file if it already exists; if
+ * something goes wrong half way through writing it, it would
+ * be better to leave the old data there than to leave it empty.
+ */
+ fd = open(fname, O_CREAT | O_WRONLY, 0600);
if (fd < 0) {
char dir[FILENAME_MAX];
make_filename(dir, INDEX_DIR);
mkdir(dir, 0700);
- fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0600);
+ fd = open(fname, O_CREAT | O_WRONLY, 0600);
}
while (len > 0) {