View Issue Details

IDProjectCategoryView StatusLast Update
0007622GNUnetset servicepublic2024-02-29 22:46
Reporterulfvonbelow Assigned ToFlorian Dold  
PrioritynormalSeverityminorReproducibilitysometimes
Status closedResolutionfixed 
Product VersionGit master 
Target Version0.19.4Fixed in Version0.19.4 
Summary0007622: In srv/setu/gnunet-service-setu_strata_estimator.c, x << 64 where x is of type uint64_t is undefined
DescriptionYou'd think it should just be 0, but according to the C standard it's undefined. This causes the undefined sanitizer to complain, naturally.
Steps To Reproduce./configure --enable-sanitizer
make
make install
make check
Additional InformationPatch attached
Tagspatch
Attached Files
0001-SETU-avoid-64-bit-shift-on-64-bit-value.patch (1,282 bytes)   
From 0e991303a8bfde69eee63c841cbdef6b9c57cd30 Mon Sep 17 00:00:00 2001
From: ulfvonbelow <strilen@tilde.club>
Date: Sun, 29 Jan 2023 05:26:48 -0600
Subject: [PATCH] SETU: avoid 64-bit shift on 64-bit value.

Shifting a 64-bit value by any more than 63 bits is undefined behavior,
apparently - at least, the sanitizers complain about it. The intuitive,
obvious result, of course, is for the result to be 0. In this case, when s ==
0, x << (64 - s) should result in 0, and (x >> s) should result in x, and the
bitwise-or of those two should be x. Which x already was.

Perhaps it should be investigated whether (x >> (64 - s)) should actually
be (x >> (63 - s)), since 0 <= s < 64.
---
 src/setu/gnunet-service-setu_strata_estimator.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/setu/gnunet-service-setu_strata_estimator.c b/src/setu/gnunet-service-setu_strata_estimator.c
index 7981cc847..43ccf3afd 100644
--- a/src/setu/gnunet-service-setu_strata_estimator.c
+++ b/src/setu/gnunet-service-setu_strata_estimator.c
@@ -85,7 +85,8 @@ salt_key (const struct IBF_Key *k_in,
   uint64_t x = k_in->key_val;
 
   /* rotate ibf key */
-  x = (x >> s) | (x << (64 - s));
+  if (s > 0)
+    x = (x >> s) | (x << (64 - s));
   k_out->key_val = x;
 }
 
-- 
2.38.1

Activities

schanzen

2023-06-01 20:26

administrator   ~0020241

released some time ago

Issue History

Date Modified Username Field Change
2023-01-29 21:17 ulfvonbelow New Issue
2023-01-29 21:17 ulfvonbelow Status new => assigned
2023-01-29 21:17 ulfvonbelow Assigned To => Florian Dold
2023-01-29 21:17 ulfvonbelow Tag Attached: bug
2023-01-29 21:17 ulfvonbelow Tag Attached: patch
2023-01-29 21:17 ulfvonbelow File Added: 0001-SETU-avoid-64-bit-shift-on-64-bit-value.patch
2023-02-06 06:15 schanzen Status assigned => resolved
2023-02-06 06:15 schanzen Resolution open => fixed
2023-02-06 06:15 schanzen Fixed in Version => 0.19.4
2023-02-06 06:19 schanzen Target Version => 0.19.4
2023-06-01 20:26 schanzen Note Added: 0020241
2023-06-01 20:26 schanzen Status resolved => closed
2024-02-29 22:46 Christian Grothoff Tag Detached: bug