diff options
-rw-r--r-- | src/gdbm.h.in | 4 | ||||
-rw-r--r-- | src/gdbmerrno.c | 3 | ||||
-rw-r--r-- | src/gdbmseq.c | 21 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/gdbm.h.in b/src/gdbm.h.in index 621abf4..8ed4f13 100644 --- a/src/gdbm.h.in +++ b/src/gdbm.h.in | |||
@@ -227,9 +227,9 @@ extern int gdbm_copy_meta (GDBM_FILE dst, GDBM_FILE src); | |||
227 | # define GDBM_FILE_CLOSE_ERROR 37 | 227 | # define GDBM_FILE_CLOSE_ERROR 37 |
228 | # define GDBM_FILE_SYNC_ERROR 38 | 228 | # define GDBM_FILE_SYNC_ERROR 38 |
229 | # define GDBM_FILE_TRUNCATE_ERROR 39 | 229 | # define GDBM_FILE_TRUNCATE_ERROR 39 |
230 | 230 | # define GDBM_BAD_HASH_ENTRY 40 | |
231 | # define _GDBM_MIN_ERRNO 0 | 231 | # define _GDBM_MIN_ERRNO 0 |
232 | # define _GDBM_MAX_ERRNO GDBM_FILE_TRUNCATE_ERROR | 232 | # define _GDBM_MAX_ERRNO GDBM_BAD_HASH_ENTRY |
233 | 233 | ||
234 | /* This one was never used and will be removed in the future */ | 234 | /* This one was never used and will be removed in the future */ |
235 | # define GDBM_UNKNOWN_UPDATE GDBM_UNKNOWN_ERROR | 235 | # define GDBM_UNKNOWN_UPDATE GDBM_UNKNOWN_ERROR |
diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c index 0fa667a..309ebbc 100644 --- a/src/gdbmerrno.c +++ b/src/gdbmerrno.c | |||
@@ -139,7 +139,8 @@ const char * const gdbm_errlist[_GDBM_MAX_ERRNO+1] = { | |||
139 | [GDBM_BAD_DIR_ENTRY] = N_("Invalid directory entry"), | 139 | [GDBM_BAD_DIR_ENTRY] = N_("Invalid directory entry"), |
140 | [GDBM_FILE_CLOSE_ERROR] = N_("Error closing file"), | 140 | [GDBM_FILE_CLOSE_ERROR] = N_("Error closing file"), |
141 | [GDBM_FILE_SYNC_ERROR] = N_("Error synchronizing file"), | 141 | [GDBM_FILE_SYNC_ERROR] = N_("Error synchronizing file"), |
142 | [GDBM_FILE_TRUNCATE_ERROR] = N_("Error truncating file") | 142 | [GDBM_FILE_TRUNCATE_ERROR] = N_("Error truncating file"), |
143 | [GDBM_BAD_HASH_ENTRY] = N_("Malformed bucket hash entry") | ||
143 | }; | 144 | }; |
144 | 145 | ||
145 | const char * | 146 | const char * |
diff --git a/src/gdbmseq.c b/src/gdbmseq.c index b655238..ef40c40 100644 --- a/src/gdbmseq.c +++ b/src/gdbmseq.c | |||
@@ -21,6 +21,22 @@ | |||
21 | 21 | ||
22 | #include "gdbmdefs.h" | 22 | #include "gdbmdefs.h" |
23 | 23 | ||
24 | static inline int | ||
25 | gdbm_valid_key_p (GDBM_FILE dbf, char *key_ptr, int key_size, int elem_loc) | ||
26 | { | ||
27 | datum key; | ||
28 | int hash, bucket, offset; | ||
29 | |||
30 | key.dptr = key_ptr; | ||
31 | key.dsize = key_size; | ||
32 | _gdbm_hash_key (dbf, key, &hash, &bucket, &offset); | ||
33 | if (hash == dbf->bucket->h_table[elem_loc].hash_value && | ||
34 | dbf->dir[bucket] == dbf->dir[dbf->bucket_dir]) | ||
35 | return 1; | ||
36 | GDBM_SET_ERRNO (dbf, GDBM_BAD_HASH_ENTRY, TRUE); | ||
37 | return 0; | ||
38 | } | ||
39 | |||
24 | /* Find and read the next entry in the hash structure for DBF starting | 40 | /* Find and read the next entry in the hash structure for DBF starting |
25 | at ELEM_LOC of the current bucket and using RETURN_VAL as the place to | 41 | at ELEM_LOC of the current bucket and using RETURN_VAL as the place to |
26 | put the data that is found. | 42 | put the data that is found. |
@@ -75,6 +91,11 @@ get_next_key (GDBM_FILE dbf, int elem_loc, datum *return_val) | |||
75 | find_data = _gdbm_read_entry (dbf, elem_loc); | 91 | find_data = _gdbm_read_entry (dbf, elem_loc); |
76 | if (!find_data) | 92 | if (!find_data) |
77 | return; | 93 | return; |
94 | /* Verify if computed hash and bucket address for the key match the | ||
95 | actual ones. Bail out if not. */ | ||
96 | if (!gdbm_valid_key_p (dbf, find_data, | ||
97 | dbf->bucket->h_table[elem_loc].key_size, elem_loc)) | ||
98 | return; | ||
78 | return_val->dsize = dbf->bucket->h_table[elem_loc].key_size; | 99 | return_val->dsize = dbf->bucket->h_table[elem_loc].key_size; |
79 | if (return_val->dsize == 0) | 100 | if (return_val->dsize == 0) |
80 | return_val->dptr = (char *) malloc (1); | 101 | return_val->dptr = (char *) malloc (1); |