summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2018-08-31 08:26:31 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-08-31 08:26:31 (GMT)
commit2ff4ae9c745d4b9e6ee36468c81554027f66c35b (patch) (side-by-side diff)
tree4a6012ba90fc9c4fc9da8bade6fb943efc38d1a0 /src
parent778cc81d55aecd6344d577919cec73e4e6980e2e (diff)
downloadgdbm-2ff4ae9c745d4b9e6ee36468c81554027f66c35b.tar.gz
gdbm-2ff4ae9c745d4b9e6ee36468c81554027f66c35b.tar.bz2
Various bugfixes.
* compat/dbmopen.c (ndbm_open_dir_file0): Ignore ENOENT. * src/falloc.c (push_avail_block): Free temporary storage no matter what return status. * src/gdbm.h.in (GDBM_FILE_TRUNCATE_ERROR): New error code. * src/gdbmdump.c (_gdbm_dump_ascii): Initialize rc. * src/gdbmerrno.c: Handle new error.code * src/gdbmload.c (gdbm_load_bdb_dump): Initialize rc * src/gdbmopen.c (_gdbm_ftruncate): New function. (gdbm_fd_open): Use _gdbm_ftruncate. Check its return. * src/gdbmseq.c (gdbm_firstkey): Initialize dsize * src/gdbmtool.c (command_generator): Check if cmd is NULL. (shouldn't happen, but anyways). * src/mmap.c (_gdbm_mapped_lseek): Check for vailidity of the 'whence' parameter. * src/systems.h (TRUNCATE): Remove macro. * src/util.c (vgetyn): Remove unnecessary assignment.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/falloc.c54
-rw-r--r--src/gdbm.h.in3
-rw-r--r--src/gdbmdump.c2
-rw-r--r--src/gdbmerrno.c6
-rw-r--r--src/gdbmload.c1
-rw-r--r--src/gdbmopen.c29
-rw-r--r--src/gdbmseq.c1
-rw-r--r--src/gdbmtool.c2
-rw-r--r--src/mmap.c4
-rw-r--r--src/systems.h7
-rw-r--r--src/util.c5
11 files changed, 75 insertions, 39 deletions
diff --git a/src/falloc.c b/src/falloc.c
index 09b40d4..7a94afb 100644
--- a/src/falloc.c
+++ b/src/falloc.c
@@ -315,29 +315,39 @@ push_avail_block (GDBM_FILE dbf)
- /* Free the unneeded space. */
- new_loc.av_adr += av_size;
- new_loc.av_size -= av_size;
- _gdbm_free (dbf, new_loc.av_adr, new_loc.av_size);
-
- /* Update the disk. */
- file_pos = gdbm_file_seek (dbf, av_adr, SEEK_SET);
- if (file_pos != av_adr)
+ rc = 0;
+ do
{
- GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
- _gdbm_fatal (dbf, _("lseek error"));
- return -1;
- }
+ /* Free the unneeded space. */
+ new_loc.av_adr += av_size;
+ new_loc.av_size -= av_size;
+ if (_gdbm_free (dbf, new_loc.av_adr, new_loc.av_size))
+ {
+ rc = -1;
+ break;
+ }
+
+ /* Update the disk. */
+ file_pos = gdbm_file_seek (dbf, av_adr, SEEK_SET);
+ if (file_pos != av_adr)
+ {
+ GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE);
+ _gdbm_fatal (dbf, _("lseek error"));
+ rc = -1;
+ break;
+ }
- rc = _gdbm_full_write (dbf, temp, av_size);
- if (rc)
- {
- GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
- "%s: error writing avail data: %s",
- dbf->name, gdbm_db_strerror (dbf));
- _gdbm_fatal (dbf, gdbm_db_strerror (dbf));
- return -1;
+ rc = _gdbm_full_write (dbf, temp, av_size);
+ if (rc)
+ {
+ GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR,
+ "%s: error writing avail data: %s",
+ dbf->name, gdbm_db_strerror (dbf));
+ _gdbm_fatal (dbf, gdbm_db_strerror (dbf));
+ rc = -1;
+ }
}
-
+ while (0);
+
free (temp);
- return 0;
+ return rc;
}
diff --git a/src/gdbm.h.in b/src/gdbm.h.in
index 6318ad8..f5eadc5 100644
--- a/src/gdbm.h.in
+++ b/src/gdbm.h.in
@@ -229,5 +229,6 @@ extern int gdbm_copy_meta (GDBM_FILE dst, GDBM_FILE src);
# define GDBM_FILE_SYNC_ERROR 38
+# define GDBM_FILE_TRUNCATE_ERROR 39
# define _GDBM_MIN_ERRNO 0
-# define _GDBM_MAX_ERRNO GDBM_FILE_SYNC_ERROR
+# define _GDBM_MAX_ERRNO GDBM_FILE_TRUNCATE_ERROR
diff --git a/src/gdbmdump.c b/src/gdbmdump.c
index 2e6f5b0..a8c4ec5 100644
--- a/src/gdbmdump.c
+++ b/src/gdbmdump.c
@@ -64,3 +64,3 @@ _gdbm_dump_ascii (GDBM_FILE dbf, FILE *fp)
size_t bufsize = 0;
- int rc;
+ int rc = 0;
diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c
index 4ce7f9d..6758272 100644
--- a/src/gdbmerrno.c
+++ b/src/gdbmerrno.c
@@ -140,3 +140,4 @@ const char * const gdbm_errlist[_GDBM_MAX_ERRNO+1] = {
[GDBM_FILE_CLOSE_ERROR] = N_("Error closing file"),
- [GDBM_FILE_SYNC_ERROR] = N_("Error synchronizing file")
+ [GDBM_FILE_SYNC_ERROR] = N_("Error synchronizing file"),
+ [GDBM_FILE_TRUNCATE_ERROR] = N_("Error truncating file")
};
@@ -184,3 +185,4 @@ int const gdbm_syserr[_GDBM_MAX_ERRNO+1] = {
[GDBM_FILE_CLOSE_ERROR] = 1,
- [GDBM_FILE_SYNC_ERROR] = 1
+ [GDBM_FILE_SYNC_ERROR] = 1,
+ [GDBM_FILE_TRUNCATE_ERROR] = 1
};
diff --git a/src/gdbmload.c b/src/gdbmload.c
index 008bcb9..f5b7869 100644
--- a/src/gdbmload.c
+++ b/src/gdbmload.c
@@ -544,2 +544,3 @@ gdbm_load_bdb_dump (struct dump_file *file, GDBM_FILE dbf, int replace)
i = 0;
+ rc = 0;
while ((c = fgetc (file->fp)) == ' ')
diff --git a/src/gdbmopen.c b/src/gdbmopen.c
index 908887c..7ec57e7 100644
--- a/src/gdbmopen.c
+++ b/src/gdbmopen.c
@@ -201,2 +201,17 @@ validate_header (gdbm_file_header const *hdr, struct stat const *st)
+/* Do we have ftruncate? */
+static inline int
+_gdbm_ftruncate (GDBM_FILE dbf)
+{
+#if HAVE_FTRUNCATE
+ return ftruncate (dbf->desc, 0);
+#else
+ int fd;
+ fd = open (dbf->name, O_RDWR|O_TRUNC, mode);
+ if (fd == -1)
+ return -1;
+ return close (fd);
+#endif
+}
+
GDBM_FILE
@@ -322,4 +337,13 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
{
- TRUNCATE (dbf);
- if (fstat (dbf->desc, &file_stat))
+ if (_gdbm_ftruncate (dbf))
+ {
+ GDBM_SET_ERRNO2 (dbf, GDBM_FILE_TRUNCATE_ERROR, FALSE,
+ GDBM_DEBUG_OPEN);
+ }
+ else if (fstat (dbf->desc, &file_stat))
+ {
+ GDBM_SET_ERRNO2 (dbf, GDBM_FILE_STAT_ERROR, FALSE, GDBM_DEBUG_OPEN);
+ }
+
+ if (gdbm_last_errno (dbf))
{
@@ -329,3 +353,2 @@ gdbm_fd_open (int fd, const char *file_name, int block_size,
free (dbf);
- GDBM_SET_ERRNO2 (NULL, GDBM_FILE_STAT_ERROR, FALSE, GDBM_DEBUG_OPEN);
return NULL;
diff --git a/src/gdbmseq.c b/src/gdbmseq.c
index e74d78d..ee7ebf3 100644
--- a/src/gdbmseq.c
+++ b/src/gdbmseq.c
@@ -103,2 +103,3 @@ gdbm_firstkey (GDBM_FILE dbf)
return_val.dptr = NULL;
+ return_val.dsize = 0;
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index 454465e..8c97e1e 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -1437,3 +1437,3 @@ command_generator (const char *text, int state)
- if (!cmd->name)
+ if (!cmd || !cmd->name)
return NULL;
diff --git a/src/mmap.c b/src/mmap.c
index 48e84ae..148b852 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -369,2 +369,6 @@ _gdbm_mapped_lseek (GDBM_FILE dbf, off_t offset, int whence)
}
+
+ default:
+ errno = EINVAL;
+ return -1;
}
diff --git a/src/systems.h b/src/systems.h
index 750aa51..f269060 100644
--- a/src/systems.h
+++ b/src/systems.h
@@ -54,9 +54,2 @@
-/* Do we have ftruncate? */
-#if HAVE_FTRUNCATE
-# define TRUNCATE(dbf) ftruncate (dbf->desc, 0)
-#else
-# define TRUNCATE(dbf) close( open (dbf->name, O_RDWR|O_TRUNC, mode));
-#endif
-
#ifndef STDERR_FILENO
diff --git a/src/util.c b/src/util.c
index f254202..3493366 100644
--- a/src/util.c
+++ b/src/util.c
@@ -100,4 +100,5 @@ vgetyn (const char *prompt, va_list ap)
}
- state = 0;
- } else
+ /* fall through */
+ }
+ else
break;

Return to:

Send suggestions and report system problems to the System administrator.