diff mbox series

Fix missing randomness in __gen_tempname (bug 32214)

Message ID mvmtte26asa.fsf@suse.de
State New
Headers show
Series Fix missing randomness in __gen_tempname (bug 32214) | expand

Commit Message

Andreas Schwab Sept. 26, 2024, 9:09 a.m. UTC
Make sure to update the random value also if getrandom fails.

Fixes: 686d542025 ("posix: Sync tempname with gnulib")
---
 sysdeps/posix/tempname.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Florian Weimer Sept. 26, 2024, 9:31 a.m. UTC | #1
* Andreas Schwab:

> Make sure to update the random value also if getrandom fails.
>
> Fixes: 686d542025 ("posix: Sync tempname with gnulib")
> ---
>  sysdeps/posix/tempname.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
> index c00fe0c181..fc30958a0c 100644
> --- a/sysdeps/posix/tempname.c
> +++ b/sysdeps/posix/tempname.c
> @@ -117,6 +117,8 @@ random_bits (random_value *r, random_value s)
>       succeed.  */
>  #if !_LIBC
>    *r = mix_random_values (v, clock ());
> +#else
> +  *r = v;
>  #endif
>    return false;
>  }

Does misc/tst-mkfstemp-fuse-parallel catch this by chance?

Change looks good.

Thanks,
Florian
Andreas Schwab Sept. 26, 2024, 9:44 a.m. UTC | #2
On Sep 26 2024, Florian Weimer wrote:

> Does misc/tst-mkfstemp-fuse-parallel catch this by chance?

Did you mean misc/tst-mkstemp-fuse-parallel?

No, the error only happens if getrandom fails.
Florian Weimer Sept. 26, 2024, 9:47 a.m. UTC | #3
* Andreas Schwab:

> On Sep 26 2024, Florian Weimer wrote:
>
>> Does misc/tst-mkfstemp-fuse-parallel catch this by chance?
>
> Did you mean misc/tst-mkstemp-fuse-parallel?

Yes.

> No, the error only happens if getrandom fails.

Sure, but if we inject an error into the test, will it detect the lack
of randomness?

Thanks,
Florian
Andreas Schwab Sept. 26, 2024, 10:34 a.m. UTC | #4
On Sep 26 2024, Florian Weimer wrote:

> Sure, but if we inject an error into the test, will it detect the lack
> of randomness?

Most likely, since the generated file name is constant and predictable.
diff mbox series

Patch

diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c
index c00fe0c181..fc30958a0c 100644
--- a/sysdeps/posix/tempname.c
+++ b/sysdeps/posix/tempname.c
@@ -117,6 +117,8 @@  random_bits (random_value *r, random_value s)
      succeed.  */
 #if !_LIBC
   *r = mix_random_values (v, clock ());
+#else
+  *r = v;
 #endif
   return false;
 }