[3/4] corpus: Handle empty symbol table cases

Message ID 877cwzt1f8.fsf_-_@redhat.com
State New
Headers
Series Fix duplicated corpora in corpus group |

Commit Message

Dodji Seketeli Feb. 3, 2023, 11:48 a.m. UTC
  Hello,

There can be cases where the symbol table associated with a given
corpus is empty.  This patch handles those cases to avoid crashes.

	* src/abg-corpus.cc (corpus::priv::{get_sorted_fun_symbols,
	get_sorted_undefined_fun_symbols, get_sorted_var_symbols,
	get_sorted_undefined_var_symbols}): If the symbol is null, then
	return an empty vector of symbols.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 src/abg-corpus.cc | 58 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 18 deletions(-)
  

Patch

diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc
index b6f760bb..4f20a888 100644
--- a/src/abg-corpus.cc
+++ b/src/abg-corpus.cc
@@ -313,9 +313,15 @@  corpus::priv::get_sorted_fun_symbols() const
 {
   if (!sorted_fun_symbols)
     {
-      auto filter = symtab_->make_filter();
-      filter.set_functions();
-      sorted_fun_symbols = elf_symbols(symtab_->begin(filter), symtab_->end());
+      if (symtab_)
+	{
+	  auto filter = symtab_->make_filter();
+	  filter.set_functions();
+	  sorted_fun_symbols = elf_symbols(symtab_->begin(filter),
+					   symtab_->end());
+	}
+      else
+	sorted_fun_symbols = elf_symbols();
     }
   return *sorted_fun_symbols;
 }
@@ -349,13 +355,18 @@  corpus::priv::get_sorted_undefined_fun_symbols() const
 {
   if (!sorted_undefined_fun_symbols)
     {
-      auto filter = symtab_->make_filter();
-      filter.set_functions();
-      filter.set_undefined_symbols();
-      filter.set_public_symbols(false);
+      if (symtab_)
+	{
+	  auto filter = symtab_->make_filter();
+	  filter.set_functions();
+	  filter.set_undefined_symbols();
+	  filter.set_public_symbols(false);
 
-      sorted_undefined_fun_symbols =
-	elf_symbols(symtab_->begin(filter), symtab_->end());
+	  sorted_undefined_fun_symbols =
+	    elf_symbols(symtab_->begin(filter), symtab_->end());
+	}
+      else
+	sorted_undefined_fun_symbols = elf_symbols();
     }
   return *sorted_undefined_fun_symbols;
 }
@@ -446,10 +457,16 @@  corpus::priv::get_sorted_var_symbols() const
 {
   if (!sorted_var_symbols)
     {
-      auto filter = symtab_->make_filter();
-      filter.set_variables();
+      if (symtab_)
+	{
+	  auto filter = symtab_->make_filter();
+	  filter.set_variables();
 
-      sorted_var_symbols = elf_symbols(symtab_->begin(filter), symtab_->end());
+	  sorted_var_symbols = elf_symbols(symtab_->begin(filter),
+					   symtab_->end());
+	}
+      else
+	sorted_var_symbols = elf_symbols();
     }
   return *sorted_var_symbols;
 }
@@ -483,13 +500,18 @@  corpus::priv::get_sorted_undefined_var_symbols() const
 {
   if (!sorted_undefined_var_symbols)
     {
-      auto filter = symtab_->make_filter();
-      filter.set_variables();
-      filter.set_undefined_symbols();
-      filter.set_public_symbols(false);
+      if (symtab_)
+	{
+	  auto filter = symtab_->make_filter();
+	  filter.set_variables();
+	  filter.set_undefined_symbols();
+	  filter.set_public_symbols(false);
 
-      sorted_undefined_var_symbols =
-	  elf_symbols(symtab_->begin(filter), symtab_->end());
+	  sorted_undefined_var_symbols =
+	    elf_symbols(symtab_->begin(filter), symtab_->end());
+	}
+      else
+	sorted_undefined_var_symbols = elf_symbols();
     }
   return *sorted_undefined_var_symbols;
 }