зеркало из https://github.com/github/putty.git
Improve robustness in random seed file handling.
[originally from svn r2200]
This commit is contained in:
Родитель
7c95ea19c8
Коммит
a1125a8052
3
noise.c
3
noise.c
|
@ -40,6 +40,8 @@ void noise_get_heavy(void (*func) (void *, int))
|
||||||
}
|
}
|
||||||
|
|
||||||
read_random_seed(func);
|
read_random_seed(func);
|
||||||
|
/* Update the seed immediately, in case another instance uses it. */
|
||||||
|
random_save_seed();
|
||||||
|
|
||||||
gsps = NULL;
|
gsps = NULL;
|
||||||
mod = GetModuleHandle("KERNEL32");
|
mod = GetModuleHandle("KERNEL32");
|
||||||
|
@ -56,6 +58,7 @@ void random_save_seed(void)
|
||||||
if (random_active) {
|
if (random_active) {
|
||||||
random_get_savedata(&data, &len);
|
random_get_savedata(&data, &len);
|
||||||
write_random_seed(data, len);
|
write_random_seed(data, len);
|
||||||
|
sfree(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,10 @@ int random_byte(void)
|
||||||
|
|
||||||
void random_get_savedata(void **data, int *len)
|
void random_get_savedata(void **data, int *len)
|
||||||
{
|
{
|
||||||
|
void *buf = smalloc(POOLSIZE / 2);
|
||||||
random_stir();
|
random_stir();
|
||||||
*data = pool.pool + pool.poolpos;
|
memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2);
|
||||||
*len = POOLSIZE / 2;
|
*len = POOLSIZE / 2;
|
||||||
|
*data = buf;
|
||||||
|
random_stir();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ void noise_get_heavy(void (*func) (void *, int))
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
|
|
||||||
read_random_seed(func);
|
read_random_seed(func);
|
||||||
|
random_save_seed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void random_save_seed(void)
|
void random_save_seed(void)
|
||||||
|
@ -72,6 +73,7 @@ void random_save_seed(void)
|
||||||
if (random_active) {
|
if (random_active) {
|
||||||
random_get_savedata(&data, &len);
|
random_get_savedata(&data, &len);
|
||||||
write_random_seed(data, len);
|
write_random_seed(data, len);
|
||||||
|
sfree(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,13 +318,18 @@ void write_random_seed(void *data, int len)
|
||||||
char fname[FILENAME_MAX];
|
char fname[FILENAME_MAX];
|
||||||
|
|
||||||
make_filename(fname, INDEX_RANDSEED);
|
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) {
|
if (fd < 0) {
|
||||||
char dir[FILENAME_MAX];
|
char dir[FILENAME_MAX];
|
||||||
|
|
||||||
make_filename(dir, INDEX_DIR);
|
make_filename(dir, INDEX_DIR);
|
||||||
mkdir(dir, 0700);
|
mkdir(dir, 0700);
|
||||||
fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0600);
|
fd = open(fname, O_CREAT | O_WRONLY, 0600);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче