abg-dwarf-reader: zero initialize local Dwarf_Addr values

Message ID 20200203163503.250026-1-maennich@google.com
State Committed
Headers
Series abg-dwarf-reader: zero initialize local Dwarf_Addr values |

Commit Message

Aleksei Vetrov via Libabigail Jan. 1, 2020, midnight UTC
  Not initializing those might lead to undefined behaviour. E.g. if the
call to 'dwarf_ranges' does not initialize 'addr', we pass that
uninitialized value to 'maybe_adjust_fn_sym_address' and test it for
zero as first action, depending on the random value. Hence, fix that by
initializing the values.

	* src/abg-dwarf-reader.cc
	(read_context::get_first_exported_fn_address_from_DW_AT_ranges):
	initialize local Dwarf_Addr variables.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-dwarf-reader.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Aleksei Vetrov via Libabigail Jan. 1, 2020, midnight UTC | #1
On Tue, Feb 04, 2020 at 09:38:22AM +0100, Dodji Seketeli wrote:
>Hello Matthias,
>
>Matthias Maennich <maennich@google.com> a ?crit:
>
>> Not initializing those might lead to undefined behaviour. E.g. if the
>> call to 'dwarf_ranges' does not initialize 'addr', we pass that
>> uninitialized value to 'maybe_adjust_fn_sym_address' and test it for
>> zero as first action, depending on the random value. Hence, fix that by
>> initializing the values.
>>
>> 	* src/abg-dwarf-reader.cc
>> 	(read_context::get_first_exported_fn_address_from_DW_AT_ranges):
>> 	initialize local Dwarf_Addr variables.
>
>This is OK to commit to master.

And done!

Cheers,
Matthias

>
>Thanks!
>
>-- 
>		Dodji
  
Dodji Seketeli Jan. 1, 2020, midnight UTC | #2
Hello Matthias,

Matthias Maennich <maennich@google.com> a ?crit:

> Not initializing those might lead to undefined behaviour. E.g. if the
> call to 'dwarf_ranges' does not initialize 'addr', we pass that
> uninitialized value to 'maybe_adjust_fn_sym_address' and test it for
> zero as first action, depending on the random value. Hence, fix that by
> initializing the values.
>
> 	* src/abg-dwarf-reader.cc
> 	(read_context::get_first_exported_fn_address_from_DW_AT_ranges):
> 	initialize local Dwarf_Addr variables.

This is OK to commit to master.

Thanks!
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index f6ab72c7dabb..436f6102870e 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -8747,7 +8747,7 @@  public:
 
     do
       {
-	Dwarf_Addr addr, fn_addr;
+	Dwarf_Addr addr = 0, fn_addr = 0;
 	if ((offset = dwarf_ranges(die, offset, &base, &addr, &end_addr)) >= 0)
 	  {
 	    fn_addr = maybe_adjust_fn_sym_address(addr);