merge: Add merge comment

The merge code tries to add a comment about what file names
are part of the merge. However, it's been doing so by appending
that comment information to the first comment in the first SHB
of the first source file, and doing nothing if there isn't an
existing comment.

Ensure that the comment is always there by adding the comment
instead. Perhaps it should be prepended instead.

Fix #13839
This commit is contained in:
John Thacker 2023-10-15 08:48:43 -04:00
parent a4b6cd460d
commit 64937eb552
1 changed files with 7 additions and 10 deletions

View File

@ -490,7 +490,6 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
GString *comment_gstr;
GString *os_info_str;
guint i;
char* shb_comment = NULL;
wtapng_section_mandatory_t* shb_data;
gsize opt_len;
gchar *opt_str;
@ -505,14 +504,7 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
*
* XXX - do we want some way to record which comments, hardware/OS/app
* descriptions, IDBs, etc.? came from which files?
*
* XXX - fix this to handle multiple comments from a single file.
*/
if (wtap_block_get_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, &shb_comment) == WTAP_OPTTYPE_SUCCESS &&
strlen(shb_comment) > 0) {
/* very lame way to save comments - does not save them from the other files */
g_string_append_printf(comment_gstr, "%s \n",shb_comment);
}
g_string_append_printf(comment_gstr, "File created by merging: \n");
@ -527,9 +519,14 @@ create_shb_header(const merge_in_file_t *in_files, const guint in_file_count,
shb_data->section_length = -1;
/* TODO: handle comments from each file being merged */
opt_len = comment_gstr->len;
/* XXX: 65535 is the maximum size for an option (hence comment) in pcapng.
* Truncate it? Let wiretap/pcapng.c decide what to do? (Currently it
* writes nothing without reporting an error.) What if we support other
* output file formats later?
*/
opt_str = g_string_free(comment_gstr, FALSE);
wtap_block_set_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, opt_str, opt_len); /* section comment */
g_free(opt_str);
/* XXX: We probably want to prepend (insert at index 0) instead? */
wtap_block_add_string_option_owned(shb_hdr, OPT_COMMENT, opt_str);
/*
* XXX - and how do we preserve all the OPT_SHB_HARDWARE, OPT_SHB_OS,
* and OPT_SHB_USERAPPL values from all the previous files?