From 6ada227e9fa2663cfe5efcf9b8ff332c23ef4fc4 Mon Sep 17 00:00:00 2001 From: w00348538 Date: Fri, 4 Sep 2020 16:00:00 +0800 Subject: [PATCH] TicketNo:DTS2020090402983 Description: change fread to read Team:EMUI Feature or Bugfix:Bugfix Binary Source:No PrivateCode(Yes/No):No Change-Id: I2d2f0d309d8d1b60976b139f6b0b5f7b5b76b038 Reviewed-on: http://mgit-tm.rnd.huawei.com/10633471 Tested-by: public jenkins Reviewed-by: wangjing 00270068 --- library/entropy_poll.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) mode change 100644 => 100755 library/entropy_poll.c diff --git a/library/entropy_poll.c b/library/entropy_poll.c old mode 100644 new mode 100755 index 4556f88..f0b12fa --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -115,12 +115,12 @@ static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags ) #endif /* __linux__ */ #include +#include +#include int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen ) { - FILE *file; - size_t read_len; int ret; ((void) data); @@ -140,18 +140,18 @@ int mbedtls_platform_entropy_poll( void *data, *olen = 0; - file = fopen( "/dev/urandom", "rb" ); - if( file == NULL ) + int fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); - read_len = fread( output, 1, len, file ); - if( read_len != len ) + ssize_t read_len = read(fd, output, len); + if ((read_len == -1) || ((size_t)read_len != len)) { - fclose( file ); + close(fd); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } - fclose( file ); + close(fd); *olen = len; return( 0 ); -- GitLab