From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1208B46BCE for ; Tue, 4 Jul 2023 22:21:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3263868C62D; Wed, 5 Jul 2023 01:21:16 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F01568C61F for ; Wed, 5 Jul 2023 01:21:10 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EC405E8C2D for ; Wed, 5 Jul 2023 00:18:27 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kIY9ivSCTSfZ for ; Wed, 5 Jul 2023 00:18:22 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id ACEBCE8C0E for ; Wed, 5 Jul 2023 00:18:22 +0200 (CEST) Date: Wed, 5 Jul 2023 00:18:22 +0200 (CEST) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20230704204128.2510-1-jamrial@gmail.com> Message-ID: References: <20230704204128.2510-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] avutil/random_seed: add av_random() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, 4 Jul 2023, James Almer wrote: > Uses the existing code for av_get_random_seed() to return a buffer with > cryptographically secure random data, or an error if none could be generated. > > Signed-off-by: James Almer > --- > libavutil/random_seed.c | 54 ++++++++++++++++++++++++++++------------- > libavutil/random_seed.h | 12 +++++++++ > 2 files changed, 49 insertions(+), 17 deletions(-) > > diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c > index 66dd504ef0..0ed8f89cc6 100644 > --- a/libavutil/random_seed.c > +++ b/libavutil/random_seed.c > @@ -46,20 +46,22 @@ > #define TEST 0 > #endif > > -static int read_random(uint32_t *dst, const char *file) > -{ > #if HAVE_UNISTD_H > +static int read_random(uint8_t *dst, size_t len, const char *file) Maybe it is cleaner if you also use ffmpeg error codes for this function, and no special -1, 1 or 0 return value. > +{ > int fd = avpriv_open(file, O_RDONLY); > - int err = -1; > + ssize_t err = -1; > > + if (len > SSIZE_MAX) > + return -1; > if (fd == -1) > return -1; > - err = read(fd, dst, sizeof(*dst)); > + err = read(fd, dst, len); As Anton pointed out, this can read less than requested. I suggest using avpriv_fopen_utf8() and fread(), that should loop reading internally until the whole length is filled. Regards, Marton _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".