From ee6c7128ed0d58cb1812049463a13bba9cfb31b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 6 Nov 2015 01:42:41 +0100 Subject: Imported Upstream version 2.9.7 --- lib/lanplus/lanplus_crypt_impl.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/lanplus/lanplus_crypt_impl.c') diff --git a/lib/lanplus/lanplus_crypt_impl.c b/lib/lanplus/lanplus_crypt_impl.c index 3f9679e..d12ad9c 100644 --- a/lib/lanplus/lanplus_crypt_impl.c +++ b/lib/lanplus/lanplus_crypt_impl.c @@ -61,13 +61,20 @@ int lanplus_seed_prng(uint32_t bytes) static FILE *fp = NULL; size_t i; randfile = RAND_file_name(buffer, sizeof buffer); /* usu C:\.rnd */ - if ((randfile != NULL) && (fp == NULL)) { - /*first time, so open/create file*/ - fp = fopen(randfile,"w"); /*create the randfile*/ - if (fp != NULL) { - i = fwrite(" \n",2,1,fp); - fclose(fp); - } + if ((randfile != NULL) && (fp == NULL)) { + fp = fopen(randfile,"r"); /*check the randfile*/ + if (fp == NULL) { /*does not exist, create it*/ + /*first time, so open/create file*/ + fp = fopen(randfile,"w"); /*create the randfile*/ + if (fp != NULL) { + i = fwrite(" \n",2,1,fp); + fclose(fp); + } else { + printf("seed_prng: cannot create %s file\n",randfile); + } + } else { /*file opened, so close it*/ + fclose(fp); + } } if (verbose > 0) printf("seed_prng: RAND_file_name = %s, fp=%p\n",randfile,fp); -- cgit v1.2.3