From 24f6717ddf09a5e00eb476b066be4b2291c62a1e Mon Sep 17 00:00:00 2001 From: Alhuda Khan Date: Fri, 20 Nov 2026 08:11:31 +0000 Subject: [PATCH] binutils: validate DW_LNE_define_file filename bounds Signed-off-by: Alhuda Khan --- binutils/dwarf.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 5ca18ff2073..5088b5305d9 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -6874,24 +6874,29 @@ display_debug_lines_decoded (struct dwarf_section * section, state_machine_regs.view = 0; break; case DW_LNE_define_file: - file_table = (File_Entry *) xrealloc - (file_table, (n_files + 1) * sizeof (File_Entry)); - - ++state_machine_regs.last_file_entry; - /* Source file name. */ - file_table[n_files].name = (char *) op_code_data; - op_code_data += strlen ((char *) op_code_data) + 1; - /* Directory index. */ - READ_ULEB (file_table[n_files].directory_index, - op_code_data, op_code_end); - /* Last modification time. */ - READ_ULEB (file_table[n_files].modification_date, - op_code_data, op_code_end); - /* File length. */ - READ_ULEB (file_table[n_files].length, - op_code_data, op_code_end); - n_files++; - break; + { + unsigned char *name_end = (unsigned char *) + memchr (op_code_data, '\0', op_code_end - op_code_data); + + if (name_end == NULL) + { + warn (_("DW_LNE_define_file: unterminated file name\n")); + break; + } + + file_table = (File_Entry *) xrealloc + (file_table, (n_files + 1) * sizeof (File_Entry)); + + ++state_machine_regs.last_file_entry; + file_table[n_files].name = (char *) op_code_data; + op_code_data = name_end + 1; + + READ_ULEB (file_table[n_files].directory_index, op_code_data, op_code_end); + READ_ULEB (file_table[n_files].modification_date, op_code_data, op_code_end); + READ_ULEB (file_table[n_files].length, op_code_data, op_code_end); + n_files++; + break; + } case DW_LNE_set_discriminator: case DW_LNE_HP_set_sequence: -- 2.53.0