_bfd_mul_overflow
[deliverable/binutils-gdb.git] / bfd / coffgen.c
index 5287130490ecd7b869da0c0c47594ddd9d38d0d8..20cee0a74c584281cdac0fb21617702c68d8486d 100644 (file)
@@ -1639,30 +1639,29 @@ copy_name (bfd *abfd, char *name, size_t maxlen)
 bfd_boolean
 _bfd_coff_get_external_symbols (bfd *abfd)
 {
-  bfd_size_type symesz;
-  bfd_size_type size;
+  size_t symesz;
+  size_t size;
   void * syms;
   ufile_ptr filesize;
 
   if (obj_coff_external_syms (abfd) != NULL)
     return TRUE;
 
-  symesz = bfd_coff_symesz (abfd);
-  size = obj_raw_syment_count (abfd) * symesz;
-  if (size == 0)
-    return TRUE;
-
   /* Check for integer overflow and for unreasonable symbol counts.  */
   filesize = bfd_get_file_size (abfd);
-  if (size < obj_raw_syment_count (abfd)
+  symesz = bfd_coff_symesz (abfd);
+  if (_bfd_mul_overflow (obj_raw_syment_count (abfd), symesz, &size)
       || (filesize != 0 && size > filesize))
-
     {
+      bfd_set_error (bfd_error_file_truncated);
       _bfd_error_handler (_("%pB: corrupt symbol count: %#" PRIx64 ""),
                          abfd, (uint64_t) obj_raw_syment_count (abfd));
       return FALSE;
     }
 
+  if (size == 0)
+    return TRUE;
+
   syms = bfd_malloc (size);
   if (syms == NULL)
     {
This page took 0.024481 seconds and 4 git commands to generate.