From b3ce4c493a6920b160e7ecd251fcc694891d3446 Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Fri, 9 Aug 2019 07:59:44 -0700 Subject: [PATCH] The interminable rework of afs_random() Commit f0a3d477d6109697645cfdcc17617b502349d91b restructured the operation on tv_usec to avoid using undefined behavior, but in the process introduced a behavior change. Historically (at least as far back as AFS-3.3), we masked off the low nybble (four bits) of tv_usec before adding the low byte (eight bits) of the rxi_getaddr() output. Why there was a desire to combine two sources of input for the overlapping four bits remains unclear, but restore the historical behavior for now, as the intent of commit f0a3d477d6109697645cfdcc17617b502349d91b was to not introduce any behavior changes. Reviewed-on: https://gerrit.openafs.org/13759 Reviewed-by: Cheyenne Wills Reviewed-by: Benjamin Kaduk Tested-by: BuildBot (cherry picked from commit 1c4e94da2a8fce9d79006ad6d6673d3d7de117d3) Change-Id: Iec10673e5ec73c1e0edcc231690cb6133fce8691 Reviewed-on: https://gerrit.openafs.org/13879 Reviewed-by: Michael Meffie Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Stephan Wiesand --- src/afs/afs_server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/afs/afs_server.c b/src/afs/afs_server.c index 327c0c5b9..68fefc68b 100644 --- a/src/afs/afs_server.c +++ b/src/afs/afs_server.c @@ -824,11 +824,11 @@ afs_random(void) osi_timeval_t t; osi_GetTime(&t); /* - * Clear the low byte of tv_usec in a size-independent manner before adding + * Clear the low nybble of tv_usec in a size-independent manner before adding * in the rest of the state. */ state = t.tv_usec; - state ^= (state & 0xff); + state ^= (state & 0x0f); state += rxi_getaddr() & 0xff; state += (t.tv_sec & 0xff); for (i = 0; i < 30; i++) { -- 2.39.5