[2/2] resolv: make res_randomid use random_bits()

Message ID 20210806191749.4620-2-crrodriguez@opensuse.org
State Committed
Headers
Series [1/2] Linux: implement getloadavg(3) using sysinfo(2) |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Cristian Rodríguez Aug. 6, 2021, 7:17 p.m. UTC
  It is at least "more random" than 0xffff & __getpid ();

Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
---
 resolv/res_randomid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Cristian Rodríguez Aug. 12, 2021, 6:51 p.m. UTC | #1
Ping..

On Fri, Aug 6, 2021 at 3:18 PM Cristian Rodríguez
<crrodriguez@opensuse.org> wrote:
>
> It is at least "more random" than 0xffff & __getpid ();
>
> Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
> ---
>  resolv/res_randomid.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/resolv/res_randomid.c b/resolv/res_randomid.c
> index 546daf4c8b..08a52a111a 100644
> --- a/resolv/res_randomid.c
> +++ b/resolv/res_randomid.c
> @@ -84,9 +84,10 @@
>
>  #include <resolv.h>
>  #include <unistd.h>
> +#include <random-bits.h>
>
>  unsigned int
>  res_randomid (void) {
> -  return 0xffff & __getpid ();
> +  return random_bits();
>  }
>  libc_hidden_def (__res_randomid)
> --
> 2.32.0
  
Florian Weimer Aug. 20, 2021, 7 a.m. UTC | #2
* Cristian Rodríguez:

> It is at least "more random" than 0xffff & __getpid ();
>
> Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
> ---
>  resolv/res_randomid.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/resolv/res_randomid.c b/resolv/res_randomid.c
> index 546daf4c8b..08a52a111a 100644
> --- a/resolv/res_randomid.c
> +++ b/resolv/res_randomid.c
> @@ -84,9 +84,10 @@
>  
>  #include <resolv.h>
>  #include <unistd.h>
> +#include <random-bits.h>
>  
>  unsigned int
>  res_randomid (void) {
> -  return 0xffff & __getpid ();
> +  return random_bits();
>  }
>  libc_hidden_def (__res_randomid)

The masking with 0xffff needs to remain, and there should be a space
before ().

Thanks,
Florian
  
Cristian Rodríguez Aug. 20, 2021, 1:23 p.m. UTC | #3
On Fri, Aug 20, 2021 at 3:00 AM Florian Weimer <fweimer@redhat.com> wrote:

> >  libc_hidden_def (__res_randomid)
>
> The masking with 0xffff needs to remain,

arrgh..damn !  id is an unsigned short..
you are right.

 and there should be a space
> before ().

Ok thanks..
  

Patch

diff --git a/resolv/res_randomid.c b/resolv/res_randomid.c
index 546daf4c8b..08a52a111a 100644
--- a/resolv/res_randomid.c
+++ b/resolv/res_randomid.c
@@ -84,9 +84,10 @@ 
 
 #include <resolv.h>
 #include <unistd.h>
+#include <random-bits.h>
 
 unsigned int
 res_randomid (void) {
-  return 0xffff & __getpid ();
+  return random_bits();
 }
 libc_hidden_def (__res_randomid)