[PATCH 21.5] dumper fixes for problems Coverity Scan found
Marcus Crestani <[email protected]> Sat, 13 Dec 2014 14:47:17 +0100
| Newsgroups | gmane.emacs.xemacs.patches |
|---|---|
| Message-ID | <[email protected]> |
PATCH 21.5 Coverity Scan reports some problems in dumper.c. Here a four changesets that fix the reported problems: diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2014-12-13 Marcus Crestani <[email protected]> + + * dumper.c (pdump): fdopen returns NULL when it fails. + 2014-12-05 Jerry James <[email protected]> * src/fileio.c (Ffile_truename): Fix off-by-one error. diff --git a/src/dumper.c b/src/dumper.c --- a/src/dumper.c +++ b/src/dumper.c @@ -2135,7 +2135,7 @@ report_file_error ("Unable to open dump file", build_ascstring (EMACS_PROGNAME ".dmp")); pdump_out = fdopen (pdump_fd, "w"); - if (pdump_out < 0) + if (pdump_out == NULL) report_file_error ("Unable to open dump file for writing", build_ascstring (EMACS_PROGNAME ".dmp")); +2014-12-13 Marcus Crestani <[email protected]> + + * dumper.c (pdump_file_get): Check return value of lseek. + 2014-12-13 Marcus Crestani <[email protected]> * dumper.c (pdump): fdopen returns NULL when it fails. diff --git a/src/dumper.c b/src/dumper.c --- a/src/dumper.c +++ b/src/dumper.c @@ -2553,7 +2553,11 @@ return 0; } - lseek (fd, 0, SEEK_SET); + if (lseek (fd, 0, SEEK_SET) == -1) + { + retry_close (fd); + return 0; + } #ifdef HAVE_MMAP /* Unix 98 requires that sys/mman.h define MAP_FAILED, diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2014-12-13 Marcus Crestani <[email protected]> + + * dumper.c (pdump_align_stream): + * dumper.c (pdump): Check return value of fseek. + 2014-12-13 Marcus Crestani <[email protected]> * dumper.c (pdump_file_get): Check return value of lseek. diff --git a/src/dumper.c b/src/dumper.c --- a/src/dumper.c +++ b/src/dumper.c @@ -206,7 +206,13 @@ OFF_T offset = FTELL (stream); OFF_T adjustment = ALIGN_SIZE (offset, alignment) - offset; if (adjustment) - FSEEK (stream, adjustment, SEEK_CUR); + { + if (FSEEK (stream, adjustment, SEEK_CUR) == -1) + { + report_file_error ("Unable to fseek dump file", + build_ascstring (EMACS_PROGNAME ".dmp")); + } + } } #define PDUMP_ALIGN_OUTPUT(type) pdump_align_stream (pdump_out, ALIGNOF (type)) @@ -2168,7 +2174,11 @@ elt->fcts->convert_free(elt->object, elt->data, elt->size); } - FSEEK (pdump_out, header.stab_offset, SEEK_SET); + if (FSEEK (pdump_out, header.stab_offset, SEEK_SET) == -1) + { + report_file_error ("Unable to fseek dump file", + build_ascstring (EMACS_PROGNAME ".dmp")); + } #ifdef NEW_GC { diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2014-12-13 Marcus Crestani <[email protected]> + + * dumper.c (pdump_register_sub): Don't leave fields uninitialized. + 2014-12-13 Marcus Crestani <[email protected]> * dumper.c (pdump_align_stream): diff --git a/src/dumper.c b/src/dumper.c --- a/src/dumper.c +++ b/src/dumper.c @@ -850,6 +850,8 @@ { pdump_cv_ptr_info info; info.object = *(void **)rdata; + info.index = 0; + info.save_offset = 0; info.fcts = desc1->data2.funcs; if (!pdump_find_in_cv_ptr_dynarr (info.object)) { @@ -863,6 +865,8 @@ pdump_cv_data_info info; info.object = data; info.offset = offset; + info.dest_offset = 0; + info.save_offset = 0; info.fcts = desc1->data2.funcs; info.fcts->convert(rdata, &info.data, &info.size); I'll push these changes in three days if nobody objects. -- Marcus