Hello,

Sergey from upstream sent me a patch that should fix the problem. The patch initializes allocated blocks with 0 to avoid pseudo-randomness in data.

Can you test this patch before I upload a new package to unstable? I could upload to experimental first for example.

Let me know what better suits you

/Nicolas
From 29daaae01975d849b015170cae51f57c254d8e42 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <g...@gnu.org>
Date: Tue, 4 Jun 2024 18:09:55 +0300
Subject: [PATCH] Ensure any padding bytes in avail_elem are filled with 0.
Forwarded: not-needed

* src/gdbmdefs.h (avail_elem_init): New function.
* src/bucket.c: Use avail_elem_init to initialize local variables of
avail_elem type.
* src/falloc.c: Likewise.
---
 src/bucket.c   |  5 +++--
 src/falloc.c   | 16 +++++++---------
 src/gdbmdefs.h |  9 +++++++++
 3 files changed, 19 insertions(+), 11 deletions(-)

--- a/src/bucket.c
+++ b/src/bucket.c
@@ -638,8 +638,9 @@
       dbf->bucket_dir = _gdbm_bucket_dir (dbf, next_insert);
       
       /* Invalidate old cache entry. */
-      old_bucket.av_adr  = dbf->cache_mru->ca_adr;
-      old_bucket.av_size = dbf->header->bucket_size;
+      avail_elem_init (&old_bucket,
+		       dbf->header->bucket_size,
+		       dbf->cache_mru->ca_adr);
       cache_elem_free (dbf, dbf->cache_mru);
       
       /* Set dbf->bucket to the proper bucket. */
--- a/src/falloc.c
+++ b/src/falloc.c
@@ -121,8 +121,7 @@
     return 0;
 
   /* Initialize the avail element. */
-  temp.av_size = num_bytes;
-  temp.av_adr = file_adr;
+  avail_elem_init (&temp, num_bytes, file_adr);
 
   /* Is the freed space large or small? */
   if ((num_bytes >= dbf->header->block_size) || dbf->central_free)
@@ -189,9 +188,10 @@
     }
 
   /* Set up variables. */
-  new_el.av_adr = dbf->avail->next_block;
-  new_el.av_size = ( ( (dbf->avail->size * sizeof (avail_elem)) >> 1)
-			+ sizeof (avail_block));
+  avail_elem_init (&new_el,
+		   ( ( (dbf->avail->size * sizeof (avail_elem)) >> 1)
+		     + sizeof (avail_block)),
+		   dbf->avail->next_block);
 
   /* Allocate space for the block. */
   new_blk = malloc (new_el.av_size);
@@ -404,8 +404,7 @@
   avail_elem val;		/* The default return value. */
 
   /* Initialize default return value. */
-  val.av_adr = 0;
-  val.av_size = 0;
+  avail_elem_init (&val, 0, 0);
 
   /* Search for element.  List is sorted by size. */
   index = avail_lookup (size, av_table, *av_count);
@@ -480,8 +479,7 @@
   avail_elem val;
 
   /* Need at least one block. */
-  val.av_adr  = dbf->header->next_block;
-  val.av_size = dbf->header->block_size;
+  avail_elem_init (&val, dbf->header->block_size, dbf->header->next_block);
 
   /* Get enough blocks to fit the need. */
   while (val.av_size < size)
--- a/src/gdbmdefs.h
+++ b/src/gdbmdefs.h
@@ -72,6 +72,15 @@
   off_t  av_adr;                /* The file address of the available block. */
 } avail_elem;
 
+static inline void
+avail_elem_init (avail_elem *elem, int size, off_t adr)
+{
+  /* Make sure any padding in elem is filled with 0. */
+  memset (elem, 0, sizeof (*elem));
+  elem->av_size = size;
+  elem->av_adr = adr;
+}
+
 /* This is the actual table. The in-memory images of the avail blocks are
    allocated by malloc using a calculated size.  */
 typedef struct

Reply via email to