path: root/src/gdbmdefs.h
authorSergey Poznyakoff <>2018-05-24 08:35:24 (GMT)
committer Sergey Poznyakoff <>2018-05-24 08:35:24 (GMT)
commit371bb85fe378ffd0ed6ddc81985d450cef5835a3 (patch) (side-by-side diff)
tree6ab2d142b7aa1f9b29ec50b891c8293774964209 /src/gdbmdefs.h
parentf82d0b213fd2cdce80dc891906fba8d589115664 (diff)
More error checking; improve gdbm_recover
* (set-dist-date): New rule (dist-hook): Catch FIXMEs in NEWS. * NEWS: Updated. * src/findkey.c (gdbm_bucket_element_valid_p): New function. (_gdbm_read_entry): Validate the retrieved bucket element. * src/ (gdbm_recovery): New member: duplicate_keys. (GDBM_BAD_HASH_TABLE): New error code. * src/gdbmdefs.h (TYPE_WIDTH,SIGNED_TYPE_MAXIMUM) (OFF_T_MAX): New defines. (off_t_sum_ok): New function. (gdbm_bucket_element_valid_p): New prototype. * src/gdbmerrno.c: Support for GDBM_BAD_HASH_TABLE code. * src/gdbmtool.c (recover_handler): Fix argument counting. New argument 'summary' prints statistics summary at the end of the run. (export_handler,import_handler): Fix argument counting. * src/mmap.c (SUM_FILE_SIZE): Rewrite as inlined function. Add error checking. (_gdbm_mapped_remap): More error checking. * src/recover.c (run_recovery): Don't bail out on GDBM_CANNOT_REPLACE. (gdbm_recover): Initialize duplicate_keys * src/systems.h: Include limits.h
Diffstat (limited to 'src/gdbmdefs.h') (more/less context) (ignore whitespace changes)
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h
index 5305b0d..1bb519b 100644
--- a/src/gdbmdefs.h
+++ b/src/gdbmdefs.h
@@ -26,6 +26,22 @@
#define _(s) gettext (s)
#define N_(s) s
+/* The width in bits of the integer type or expression T. */
+#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
+ ((t) ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))
+/* Maximum value for off_t */
+/* Return true if A can be added to B without integer overflow */
+static inline off_t
+off_t_sum_ok (off_t a, off_t b)
+ return OFF_T_MAX - a >= b;
/* The type definitions are next. */
/* The available file space is stored in an "avail" table. The one with
@@ -93,6 +109,7 @@ typedef struct
int data_size; /* Size of associated data in the file. */
} bucket_element;
+extern int gdbm_bucket_element_valid_p (GDBM_FILE dbf, int elem_loc);
/* A bucket is a small hash table. This one consists of a number of
bucket elements plus some bookkeeping fields. The number of elements

Return to:

Send suggestions and report system problems to the System administrator.