Make bfd_byte an int8_t, flagword a uint32_t
[binutils-gdb.git] / bfd / aoutx.h
index e9b5188e8e79c31f9221ac3083ed0e20e4c06b28..6d6527640fe4b7a3df2e4c834757e311f7d26fcd 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD semi-generic back-end for a.out binaries.
-   Copyright (C) 1990-2022 Free Software Foundation, Inc.
+   Copyright (C) 1990-2023 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -451,10 +451,10 @@ FUNCTION
        aout_@var{size}_some_aout_object_p
 
 SYNOPSIS
-       const bfd_target *aout_@var{size}_some_aout_object_p
+       bfd_cleanup aout_@var{size}_some_aout_object_p
         (bfd *abfd,
          struct internal_exec *execp,
-         const bfd_target *(*callback_to_real_object_p) (bfd *));
+         bfd_cleanup (*callback_to_real_object_p) (bfd *));
 
 DESCRIPTION
        Some a.out variant thinks that the file open in @var{abfd}
@@ -2122,8 +2122,10 @@ NAME (aout, swap_ext_reloc_out) (bfd *abfd,
   if (r_extern)                                                                \
     {                                                                  \
       /* Undefined symbol.  */                                         \
-      if (r_index < bfd_get_symcount (abfd))                           \
+      if (symbols != NULL && r_index < bfd_get_symcount (abfd))                \
        cache_ptr->sym_ptr_ptr = symbols + r_index;                     \
+      else                                                             \
+       cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;   \
       cache_ptr->addend = ad;                                          \
     }                                                                  \
    else                                                                        \
@@ -2485,13 +2487,7 @@ NAME (aout, canonicalize_reloc) (bfd *abfd,
 long
 NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
 {
-  bfd_size_type count;
-
-  if (bfd_get_format (abfd) != bfd_object)
-    {
-      bfd_set_error (bfd_error_invalid_operation);
-      return -1;
-    }
+  size_t count, raw;
 
   if (asect->flags & SEC_CONSTRUCTOR)
     count = asect->reloc_count;
@@ -2507,11 +2503,21 @@ NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
       return -1;
     }
 
-  if (count >= LONG_MAX / sizeof (arelent *))
+  if (count >= LONG_MAX / sizeof (arelent *)
+      || _bfd_mul_overflow (count, obj_reloc_entry_size (abfd), &raw))
     {
       bfd_set_error (bfd_error_file_too_big);
       return -1;
     }
+  if (!bfd_write_p (abfd))
+    {
+      ufile_ptr filesize = bfd_get_file_size (abfd);
+      if (filesize != 0 && raw > filesize)
+       {
+         bfd_set_error (bfd_error_file_truncated);
+         return -1;
+       }
+    }
   return (count + 1) * sizeof (arelent *);
 }
 \f
@@ -2903,6 +2909,7 @@ NAME (aout, bfd_free_cached_info) (bfd *abfd)
     return true;
 
 #define BFCI_FREE(x) do { free (x); x = NULL; } while (0)
+  BFCI_FREE (adata (abfd).line_buf);
   BFCI_FREE (obj_aout_symbols (abfd));
 #ifdef USE_MMAP
   obj_aout_external_syms (abfd) = 0;