Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Marton Balint <cus@passwd.hu>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] avutil/random_seed: add av_random()
Date: Wed, 5 Jul 2023 00:18:22 +0200 (CEST)
Message-ID: <c97b2b34-76c9-53ff-ad56-3f9e15d93c5d@passwd.hu> (raw)
In-Reply-To: <20230704204128.2510-1-jamrial@gmail.com>



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 <jamrial@gmail.com>
> ---
> 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".

      parent reply	other threads:[~2023-07-04 22:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 20:41 James Almer
2023-07-04 20:41 ` [FFmpeg-devel] [PATCH v2 2/2] avutil/random_seed: add support for gcrypt and OpenSSL as source of randomness James Almer
2023-07-04 20:47 ` [FFmpeg-devel] [PATCH v2 1/2] avutil/random_seed: add av_random() James Almer
2023-07-04 20:54 ` Hendrik Leppkes
2023-07-04 21:35   ` James Almer
2023-07-04 23:32     ` Michael Niedermayer
2023-07-04 22:18 ` Marton Balint [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=c97b2b34-76c9-53ff-ad56-3f9e15d93c5d@passwd.hu \
    --to=cus@passwd.hu \
    --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