From: "Rémi Denis-Courmont" <remi@remlab.net> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() Date: Wed, 05 Jul 2023 18:34:51 +0300 Message-ID: <12237271.O9o76ZdvQC@basile.remlab.net> (raw) In-Reply-To: <20230704232614.2785-1-jamrial@gmail.com> Le keskiviikkona 5. heinäkuuta 2023, 2.26.12 EEST James Almer a écrit : > This ensures the requested amount of bytes is read. You're moving the problem though. Now, you may read more than necessary (and block longer than necessary) due to stdio internal buffering, which you did not disable. > Also remove /dev/random as it's no longer necessary. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > libavutil/random_seed.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c > index 66dd504ef0..a51149235b 100644 > --- a/libavutil/random_seed.c > +++ b/libavutil/random_seed.c > @@ -49,17 +49,20 @@ > static int read_random(uint32_t *dst, const char *file) > { > #if HAVE_UNISTD_H > - int fd = avpriv_open(file, O_RDONLY); > - int err = -1; > + FILE *fp = avpriv_fopen_utf8(file, "r"); > + size_t err; > > - if (fd == -1) > - return -1; > - err = read(fd, dst, sizeof(*dst)); > - close(fd); > + if (!fp) > + return AVERROR_UNKNOWN; > + err = fread(dst, 1, sizeof(*dst), fp); > + fclose(fp); > > - return err; > + if (err != sizeof(*dst)) > + return AVERROR_UNKNOWN; > + > + return 0; > #else > - return -1; > + return AVERROR(ENOSYS); > #endif > } > > @@ -138,9 +141,7 @@ uint32_t av_get_random_seed(void) > return arc4random(); > #endif > > - if (read_random(&seed, "/dev/urandom") == sizeof(seed)) > - return seed; > - if (read_random(&seed, "/dev/random") == sizeof(seed)) > + if (!read_random(&seed, "/dev/urandom")) > return seed; > return get_generic_seed(); > } -- 雷米‧德尼-库尔蒙 http://www.remlab.net/ _______________________________________________ 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".
prev parent reply other threads:[~2023-07-05 15:35 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-04 23:26 James Almer 2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 2/3] avutil/random_seed: add av_random_bytes() James Almer 2023-07-05 10:24 ` Anton Khirnov 2023-07-05 12:12 ` [FFmpeg-devel] [PATCH v4 2/4] " James Almer 2023-07-05 12:46 ` Anton Khirnov 2023-07-05 13:24 ` James Almer 2023-07-04 23:26 ` [FFmpeg-devel] [PATCH v3 3/3] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness James Almer 2023-07-05 12:56 ` Anton Khirnov 2023-07-05 13:03 ` James Almer 2023-07-06 7:52 ` Anton Khirnov 2023-07-06 17:03 ` James Almer 2023-07-06 17:56 ` Marton Balint 2023-07-06 18:36 ` James Almer 2023-07-05 12:43 ` [FFmpeg-devel] [PATCH v3 1/3] avutil/random_seed: use fread() in read_random() Anton Khirnov 2023-07-05 13:24 ` James Almer 2023-07-05 15:34 ` Rémi Denis-Courmont [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=12237271.O9o76ZdvQC@basile.remlab.net \ --to=remi@remlab.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git