This patch fixes an obscure bug in gnatfind that could cause it to
crash on references to unknown files. The crash was caused by
dereferencing an uninitialized pointer value, so it was flaky.
No test is available.

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-07-04  Bob Duff  <d...@adacore.com>

        * xref_lib.adb (Parse_X_Filename, Parse_Identifier_Info): Ignore
        unknown files. Check that File_Nr is in the range of files we
        know about. The previous code was checking the lower bound,
        but not the upper bound.

Index: xref_lib.adb
===================================================================
--- xref_lib.adb        (revision 237957)
+++ xref_lib.adb        (working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1998-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2016, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -890,9 +890,13 @@
 
       Parse_Token (Ali, Ptr, E_Name);
 
-      --  Exit if the symbol does not match
-      --  or if we have a local symbol and we do not want it
+      --  Exit if the symbol does not match or if we have a local
+      --  symbol and we do not want it or if the file is unknown.
 
+      if File.X_File = Empty_File then
+         return;
+      end if;
+
       if (not Local_Symbols and not E_Global)
         or else (Pattern.Initialized
                   and then not Match (Ali (E_Name .. Ptr - 1), Pattern.Entity))
@@ -1261,8 +1265,12 @@
          Ptr := Ptr + 1;
          Parse_Number (Ali, Ptr, File_Nr);
 
-         if File_Nr > 0 then
+         --  If the referenced file is unknown, we simply ignore it
+
+         if File_Nr in Dependencies_Tables.First .. Last (File.Dep) then
             File.X_File := File.Dep.Table (File_Nr);
+         else
+            File.X_File := Empty_File;
          end if;
 
          Parse_EOL (Ali, Ptr);

Reply via email to