@@ -431,6 +431,7 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u
431431 int i = 0 ;
432432 size_t count ;
433433 const ut8 * tmp_buf = NULL ;
434+ char * fn = NULL ;
434435
435436 if (mode == R_MODE_PRINT ) {
436437 print (" The Directory Table:\n" );
@@ -464,10 +465,12 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u
464465
465466 for (i = 0 ; i < 2 ; i ++ ) {
466467 while (buf + 1 < buf_end ) {
467- const char * filename = (const char * )buf ;
468468 size_t maxlen = R_MIN ((size_t ) (buf_end - buf - 1 ), 0xfff );
469469 ut64 id_idx , mod_time , file_len ;
470- size_t len = r_str_nlen (filename , maxlen );
470+ free (fn );
471+ fn = r_str_ndup ((const char * )buf , maxlen );
472+ r_str_ansi_strip (fn );
473+ size_t len = strlen (fn );
471474
472475 if (!len ) {
473476 buf ++ ;
@@ -512,7 +515,7 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u
512515 }
513516
514517 if (hdr -> file_names ) {
515- hdr -> file_names [count ].name = r_str_newf ("%s/%s" , r_str_get (include_dir ), filename );
518+ hdr -> file_names [count ].name = r_str_newf ("%s/%s" , r_str_get (include_dir ), fn );
516519 hdr -> file_names [count ].id_idx = id_idx ;
517520 hdr -> file_names [count ].mod_time = mod_time ;
518521 hdr -> file_names [count ].file_len = file_len ;
@@ -525,7 +528,8 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u
525528 }
526529 count ++ ;
527530 if (mode == R_MODE_PRINT && i ) {
528- print (" %d %" PFMT64d " %" PFMT64d " %" PFMT64d " %s\n" , entry_index ++ , id_idx , mod_time , file_len , filename );
531+ print (" %d %" PFMT64d " %" PFMT64d " %" PFMT64d " %s\n" ,
532+ entry_index ++ , id_idx , mod_time , file_len , fn );
529533 }
530534 }
531535 if (i == 0 ) {
@@ -544,6 +548,7 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u
544548 }
545549
546550beach :
551+ free (fn );
547552 sdb_free (sdb );
548553
549554 return buf ;
@@ -677,7 +682,6 @@ static const ut8 *parse_line_header(
677682
678683static inline void add_sdb_addrline (Sdb * s , ut64 addr , const char * file , ut64 line , int mode , PrintfCallback print ) {
679684 const char * p ;
680- char * fileline ;
681685 char offset [SDB_NUM_BUFSZ ];
682686 char * offset_ptr ;
683687
@@ -706,7 +710,10 @@ static inline void add_sdb_addrline(Sdb *s, ut64 addr, const char *file, ut64 li
706710#else
707711 p = file ;
708712#endif
709- fileline = r_str_newf ("%s|%" PFMT64d , p , line );
713+ char * fileline = r_str_newf ("%s|%" PFMT64d , p , line );
714+ r_str_ansi_strip (fileline );
715+ r_str_replace_ch (fileline , '\n' , 0 , true);
716+ r_str_replace_ch (fileline , '\t' , 0 , true);
710717 offset_ptr = sdb_itoa (addr , 16 , offset , sizeof (offset ));
711718 sdb_add (s , offset_ptr , fileline , 0 );
712719 sdb_add (s , fileline , offset_ptr , 0 );
@@ -1666,7 +1673,15 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len,
16661673 break ;
16671674 case DW_FORM_string :
16681675 value -> kind = DW_AT_KIND_STRING ;
1669- value -> string .content = * buf ? r_str_ndup ((const char * )buf , buf_end - buf ) : NULL ;
1676+ if (* buf ) {
1677+ char * name = r_str_ndup ((const char * )buf , buf_end - buf );
1678+ r_str_ansi_strip (name );
1679+ r_str_replace_ch (name , '\n' , 0 , true);
1680+ r_str_replace_ch (name , '\t' , 0 , true);
1681+ value -> string .content = name ;
1682+ } else {
1683+ value -> string .content = NULL ;
1684+ }
16701685 if (value -> string .content ) {
16711686 buf += strlen (value -> string .content ) + 1 ;
16721687 }
@@ -1711,8 +1726,15 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len,
17111726 value -> kind = DW_AT_KIND_STRING ;
17121727 value -> string .offset = dwarf_read_offset (hdr -> is_64bit , & buf , buf_end );
17131728 if (debug_str && value -> string .offset < debug_str_len ) {
1714- const char * ds = (const char * )(debug_str + value -> string .offset );
1715- value -> string .content = strdup (ds ); // r_str_ndup (ds, debug_str_len - value->string.offset);
1729+ char * ds = r_str_ndup ((const char * )(debug_str + value -> string .offset ), debug_str_len );
1730+ if (ds ) {
1731+ r_str_ansi_strip (ds );
1732+ r_str_replace_ch (ds , '\n' , 0 , true);
1733+ r_str_replace_ch (ds , '\t' , 0 , true);
1734+ value -> string .content = ds ;
1735+ } else {
1736+ value -> string .content = NULL ;
1737+ }
17161738 } else {
17171739 value -> string .content = NULL ; // Means malformed DWARF, should we print error message?
17181740 }
@@ -1903,8 +1925,11 @@ static const ut8 *parse_die(const ut8 *buf, const ut8 *buf_end, RBinDwarfAbbrevD
19031925 // Or atleast it needs to rework becase there will be
19041926 // more comp units -> more comp dirs and only the last one will be kept
19051927 if (attribute -> attr_name == DW_AT_comp_dir && is_valid_string_form ) {
1906- const char * name = attribute -> string .content ;
1907- sdb_set (sdb , "DW_AT_comp_dir" , name , 0 );
1928+ char * name = strdup (attribute -> string .content );
1929+ r_str_ansi_strip (name );
1930+ r_str_replace_ch (name , '\n' , 0 , true);
1931+ r_str_replace_ch (name , '\t' , 0 , true);
1932+ sdb_set_owned (sdb , "DW_AT_comp_dir" , name , 0 );
19081933 }
19091934 die -> count ++ ;
19101935 }
0 commit comments