diff --git a/editcap.c b/editcap.c index b646167089..9a2d799cb0 100644 --- a/editcap.c +++ b/editcap.c @@ -1122,7 +1122,7 @@ process_new_idbs(wtap *wth, wtap_dumper *pdh, GArray *idbs_seen, * That mean that the abstract interface provided by libwiretap * involves WTAP_BLOCK_IF_ID_AND_INFO blocks. */ - if (wtap_file_type_subtype_supports_block(wtap_dump_file_type_subtype(pdh), + if (pdh != NULL && wtap_file_type_subtype_supports_block(wtap_dump_file_type_subtype(pdh), WTAP_BLOCK_IF_ID_AND_INFO) != BLOCK_NOT_SUPPORTED) { wtap_block_t if_data_copy; @@ -1849,11 +1849,9 @@ main(int argc, char *argv[]) while (wtap_read(wth, &read_rec, &read_buf, &read_err, &read_err_info, &data_offset)) { /* * XXX - what about non-packet records in the file after this? - * We can *probably* ignore IDBs after this point, as they - * presumably indicate that we weren't capturing on that - * interface at this point, but what about, for example, ISBs? - * (NRBs and DSBs are now written when wtap_dump_close() calls - * pcapng_dump_finish().) + * NRBs, DSBs, and ISBs are now written when wtap_dump_close() calls + * pcapng_dump_finish(), and we handle IDBs below, but what about + * custom blocks? */ if (max_packet_number <= read_count) break; @@ -2389,6 +2387,18 @@ main(int argc, char *argv[]) } } + /* + * Process whatever IDBs we haven't seen yet. + */ + if (!process_new_idbs(wth, pdh, idbs_seen, &write_err, &write_err_info)) { + cfile_write_failure_message(argv[ws_optind], filename, + write_err, write_err_info, + read_count, + out_file_type_subtype); + ret = DUMP_ERROR; + goto clean_exit; + } + if (!wtap_dump_close(pdh, NULL, &write_err, &write_err_info)) { cfile_close_failure_message(filename, write_err, write_err_info); ret = WRITE_ERROR; diff --git a/tshark.c b/tshark.c index c12cbbdeb8..f5a8cbb3c3 100644 --- a/tshark.c +++ b/tshark.c @@ -3583,9 +3583,19 @@ process_cap_file_single_pass(capture_file *cf, wtap_dumper *pdh, } wtap_rec_reset(&rec); } - if (*err != 0 && status == PASS_SUCCEEDED) { - /* Error reading from the input file. */ - status = PASS_READ_ERROR; + if (status == PASS_SUCCEEDED) { + if (*err != 0) { + /* Error reading from the input file. */ + status = PASS_READ_ERROR; + } else { + /* + * Process whatever IDBs we haven't seen yet. + */ + if (!process_new_idbs(cf->provider.wth, pdh, err, err_info)) { + *err_framenum = framenum; + status = PASS_WRITE_ERROR; + } + } } if (edt) diff --git a/wiretap/merge.c b/wiretap/merge.c index ed2f5d7b5d..0c3c919acf 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -1046,7 +1046,13 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, cb->callback_func(MERGE_EVENT_DONE, count, in_files, in_file_count, cb->data); if (status == MERGE_OK || status == MERGE_USER_ABORTED) { - /* Check for any NRBs or DSBs read after the last packet records. */ + /* Check for IDBs, NRBs, or DSBs read after the last packet records. */ + if (wtap_file_type_subtype_supports_block(file_type, + WTAP_BLOCK_IF_ID_AND_INFO) != BLOCK_NOT_SUPPORTED) { + if (!process_new_idbs(pdh, in_files, in_file_count, mode, idb_inf, err, err_info)) { + status = MERGE_ERR_CANT_WRITE_OUTFILE; + } + } if (nrb_combined) { for (guint j = 0; j < in_file_count; j++) { in_file = &in_files[j]; @@ -1073,6 +1079,8 @@ merge_process_packets(wtap_dumper *pdh, const int file_type, } } } + } + if (status == MERGE_OK || status == MERGE_USER_ABORTED) { if (!wtap_dump_close(pdh, NULL, err, err_info)) status = MERGE_ERR_CANT_CLOSE_OUTFILE; } else {