1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 11:02:48 -05:00

Improve robustness in random seed file handling.

[originally from svn r2200]
This commit is contained in:
Simon Tatham
2002-11-07 20:01:04 +00:00
parent 7c95ea19c8
commit a1125a8052
4 changed files with 16 additions and 3 deletions

View File

@ -62,6 +62,7 @@ void noise_get_heavy(void (*func) (void *, int))
pclose(fp);
read_random_seed(func);
random_save_seed();
}
void random_save_seed(void)
@ -72,6 +73,7 @@ void random_save_seed(void)
if (random_active) {
random_get_savedata(&data, &len);
write_random_seed(data, len);
sfree(data);
}
}

View File

@ -318,13 +318,18 @@ void write_random_seed(void *data, int len)
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) {