Print this page
5688 ELF tools need to be more careful with dwarf data

*** 549,559 **** uchar_t *data = (uchar_t *)(_cache->c_data->d_buf); size_t datasize = _cache->c_data->d_size; Conv_dwarf_ehe_buf_t dwarf_ehe_buf; uint64_t ndx, frame_ptr, fde_cnt, tabndx; uint_t vers, frame_ptr_enc, fde_cnt_enc, table_enc; ! uint64_t initloc, initloc0; uint64_t gotaddr = 0; int cnt; for (cnt = 1; cnt < shnum; cnt++) { if (strncmp(cache[cnt].c_name, MSG_ORIG(MSG_ELF_GOT), --- 549,559 ---- uchar_t *data = (uchar_t *)(_cache->c_data->d_buf); size_t datasize = _cache->c_data->d_size; Conv_dwarf_ehe_buf_t dwarf_ehe_buf; uint64_t ndx, frame_ptr, fde_cnt, tabndx; uint_t vers, frame_ptr_enc, fde_cnt_enc, table_enc; ! uint64_t initloc, initloc0 = 0; uint64_t gotaddr = 0; int cnt; for (cnt = 1; cnt < shnum; cnt++) { if (strncmp(cache[cnt].c_name, MSG_ORIG(MSG_ELF_GOT),
*** 561,570 **** --- 561,576 ---- gotaddr = cache[cnt].c_shdr->sh_addr; break; } } + if ((data == NULL) || (datasize == 0)) { + (void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ), + file, _cache ->c_name); + return; + } + /* * Is this a .eh_frame_hdr? */ if ((uphdr && (shdr->sh_addr == uphdr->p_vaddr)) || (strncmp(_cache->c_name, MSG_ORIG(MSG_SCN_FRMHDR),
*** 585,629 **** fde_cnt_enc = data[ndx++]; table_enc = data[ndx++]; dbg_print(0, MSG_ORIG(MSG_UNW_FRMVERS), vers); ! frame_ptr = dwarf_ehe_extract(data, &ndx, frame_ptr_enc, ! ehdr->e_ident, B_TRUE, shdr->sh_addr, ndx, gotaddr); if (eh_state->hdr_cnt == 1) { eh_state->hdr_ndx = shndx; eh_state->frame_ptr = frame_ptr; } dbg_print(0, MSG_ORIG(MSG_UNW_FRPTRENC), conv_dwarf_ehe(frame_ptr_enc, &dwarf_ehe_buf), EC_XWORD(frame_ptr)); ! fde_cnt = dwarf_ehe_extract(data, &ndx, fde_cnt_enc, ! ehdr->e_ident, B_TRUE, shdr->sh_addr, ndx, gotaddr); dbg_print(0, MSG_ORIG(MSG_UNW_FDCNENC), conv_dwarf_ehe(fde_cnt_enc, &dwarf_ehe_buf), EC_XWORD(fde_cnt)); dbg_print(0, MSG_ORIG(MSG_UNW_TABENC), conv_dwarf_ehe(table_enc, &dwarf_ehe_buf)); dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB1)); dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB2)); for (tabndx = 0; tabndx < fde_cnt; tabndx++) { ! initloc = dwarf_ehe_extract(data, &ndx, table_enc, ! ehdr->e_ident, B_TRUE, shdr->sh_addr, ndx, gotaddr); ! /*LINTED:E_VAR_USED_BEFORE_SET*/ if ((tabndx != 0) && (initloc0 > initloc)) (void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSORT), file, _cache->c_name, EC_WORD(tabndx)); dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTABENT), EC_XWORD(initloc), ! EC_XWORD(dwarf_ehe_extract(data, &ndx, ! table_enc, ehdr->e_ident, B_TRUE, shdr->sh_addr, ! ndx, gotaddr))); initloc0 = initloc; } } else { /* Display the .eh_frame section */ eh_state->frame_cnt++; if (eh_state->frame_cnt == 1) { --- 591,689 ---- fde_cnt_enc = data[ndx++]; table_enc = data[ndx++]; dbg_print(0, MSG_ORIG(MSG_UNW_FRMVERS), vers); ! switch (dwarf_ehe_extract(data, datasize, &ndx, ! &frame_ptr, frame_ptr_enc, ehdr->e_ident, B_TRUE, ! shdr->sh_addr, ndx, gotaddr)) { ! case DW_OVERFLOW: ! (void) fprintf(stderr, MSG_INTL(MSG_ERR_DWOVRFLW), ! file, _cache->c_name); ! return; ! case DW_BAD_ENCODING: ! (void) fprintf(stderr, MSG_INTL(MSG_ERR_DWBADENC), ! file, _cache->c_name, frame_ptr_enc); ! return; ! case DW_SUCCESS: ! break; ! } if (eh_state->hdr_cnt == 1) { eh_state->hdr_ndx = shndx; eh_state->frame_ptr = frame_ptr; } dbg_print(0, MSG_ORIG(MSG_UNW_FRPTRENC), conv_dwarf_ehe(frame_ptr_enc, &dwarf_ehe_buf), EC_XWORD(frame_ptr)); ! switch (dwarf_ehe_extract(data, datasize, &ndx, &fde_cnt, ! fde_cnt_enc, ehdr->e_ident, B_TRUE, shdr->sh_addr, ndx, ! gotaddr)) { ! case DW_OVERFLOW: ! (void) fprintf(stderr, MSG_INTL(MSG_ERR_DWOVRFLW), ! file, _cache->c_name); ! return; ! case DW_BAD_ENCODING: ! (void) fprintf(stderr, MSG_INTL(MSG_ERR_DWBADENC), ! file, _cache->c_name, fde_cnt_enc); ! return; ! case DW_SUCCESS: ! break; ! } dbg_print(0, MSG_ORIG(MSG_UNW_FDCNENC), conv_dwarf_ehe(fde_cnt_enc, &dwarf_ehe_buf), EC_XWORD(fde_cnt)); dbg_print(0, MSG_ORIG(MSG_UNW_TABENC), conv_dwarf_ehe(table_enc, &dwarf_ehe_buf)); dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB1)); dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB2)); for (tabndx = 0; tabndx < fde_cnt; tabndx++) { ! uint64_t table; ! ! switch (dwarf_ehe_extract(data, datasize, &ndx, ! &initloc, table_enc, ehdr->e_ident, B_TRUE, ! shdr->sh_addr, ndx, gotaddr)) { ! case DW_OVERFLOW: ! (void) fprintf(stderr, ! MSG_INTL(MSG_ERR_DWOVRFLW), file, ! _cache->c_name); ! return; ! case DW_BAD_ENCODING: ! (void) fprintf(stderr, ! MSG_INTL(MSG_ERR_DWBADENC), file, ! _cache->c_name, table_enc); ! return; ! case DW_SUCCESS: ! break; ! } if ((tabndx != 0) && (initloc0 > initloc)) (void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSORT), file, _cache->c_name, EC_WORD(tabndx)); + switch (dwarf_ehe_extract(data, datasize, &ndx, &table, + table_enc, ehdr->e_ident, B_TRUE, shdr->sh_addr, + ndx, gotaddr)) { + case DW_OVERFLOW: + (void) fprintf(stderr, + MSG_INTL(MSG_ERR_DWOVRFLW), file, + _cache->c_name); + return; + case DW_BAD_ENCODING: + (void) fprintf(stderr, + MSG_INTL(MSG_ERR_DWBADENC), file, + _cache->c_name, table_enc); + return; + case DW_SUCCESS: + break; + } + dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTABENT), EC_XWORD(initloc), ! EC_XWORD(table)); initloc0 = initloc; } } else { /* Display the .eh_frame section */ eh_state->frame_cnt++; if (eh_state->frame_cnt == 1) {
*** 635,646 **** (void) fprintf(stderr, MSG_INTL(MSG_WARN_MULTEHFRM), file, EC_WORD(shndx), _cache->c_name, conv_ehdr_type(osabi, ehdr->e_type, 0, &inv_buf)); } ! dump_eh_frame(data, datasize, shdr->sh_addr, ! ehdr->e_machine, ehdr->e_ident, gotaddr); } /* * If we've seen the .eh_frame_hdr and the first .eh_frame section, * compare the header frame_ptr to the address of the actual frame --- 695,706 ---- (void) fprintf(stderr, MSG_INTL(MSG_WARN_MULTEHFRM), file, EC_WORD(shndx), _cache->c_name, conv_ehdr_type(osabi, ehdr->e_type, 0, &inv_buf)); } ! dump_eh_frame(file, _cache->c_name, data, datasize, ! shdr->sh_addr, ehdr->e_machine, ehdr->e_ident, gotaddr); } /* * If we've seen the .eh_frame_hdr and the first .eh_frame section, * compare the header frame_ptr to the address of the actual frame
*** 734,744 **** #endif exception_range_entry scratch, *ent, *cur_ent = &scratch; char index[MAXNDXSIZE]; Word i, nelts; ! Addr addr, addr0, offset = 0; Addr exc_addr = _cache->c_shdr->sh_addr; dbg_print(0, MSG_INTL(MSG_EXR_TITLE)); ent = (exception_range_entry *)(_cache->c_data->d_buf); nelts = _cache->c_data->d_size / sizeof (exception_range_entry); --- 794,804 ---- #endif exception_range_entry scratch, *ent, *cur_ent = &scratch; char index[MAXNDXSIZE]; Word i, nelts; ! Addr addr, addr0 = 0, offset = 0; Addr exc_addr = _cache->c_shdr->sh_addr; dbg_print(0, MSG_INTL(MSG_EXR_TITLE)); ent = (exception_range_entry *)(_cache->c_data->d_buf); nelts = _cache->c_data->d_size / sizeof (exception_range_entry);
*** 761,771 **** * The table is required to be sorted by the address * derived from ret_addr, to allow binary searching. Ensure * that addresses grow monotonically. */ addr = SRELPTR(ret_addr); - /*LINTED:E_VAR_USED_BEFORE_SET*/ if ((i != 0) && (addr0 > addr)) (void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSORT), file, _cache->c_name, EC_WORD(i)); (void) snprintf(index, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX), --- 821,830 ----
*** 3679,3688 **** --- 3738,3750 ---- corenote_ret = corenote(ehdr->e_machine, do_swap, pnstate.pn_type, pnstate.pn_desc, pnstate.pn_descsz); switch (corenote_ret) { + case CORENOTE_R_OK_DUMP: + hexdump = 1; + break; case CORENOTE_R_OK: hexdump = 0; break; case CORENOTE_R_BADDATA: (void) fprintf(stderr,
*** 3696,3705 **** --- 3758,3774 ---- MSG_INTL(MSG_NOTE_BADCOREARCH), file, conv_ehdr_mach(ehdr->e_machine, 0, &inv_buf)); break; + case CORENOTE_R_BADTYPE: + (void) fprintf(stderr, + MSG_INTL(MSG_NOTE_BADCORETYPE), + file, + EC_WORD(pnstate.pn_type)); + break; + } } /* * The default thing when we don't understand
*** 4916,4925 **** --- 4985,4996 ---- case CACHE_NEEDED: if (create_cache(file, fd, elf, ehdr, &cache, shstrndx, &shnum, &flags) == 0) return (ret); break; + case CACHE_OK: + break; case CACHE_FAIL: return (ret); } if (shnum <= 1) goto done;