Don't abort for invalid input, print an error message instead.
[deliverable/binutils-gdb.git] / bfd / vms-misc.c
index 81b1fc8c92fba651200ea2a57d2c0866a0344f63..89d39dbd31967d297181212295204c35845c0915 100644 (file)
@@ -1,6 +1,6 @@
 /* vms-misc.c -- Miscellaneous functions for VAX (openVMS/VAX) and
    EVAX (openVMS/Alpha) files.
-   Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
+   Copyright 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
 
    Written by Klaus K"ampf (kkaempf@rmi.de)
 
@@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-
 #if __STDC__
 #include <stdarg.h>
 #endif
@@ -38,7 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    evaluates environment variable VMS_DEBUG for a
    numerical value on the first call
    all error levels below this value are printed
-  
+
    levels:
    1   toplevel bfd calls (functions from the bfd vector)
    2   functions called by bfd calls
@@ -74,10 +73,10 @@ _bfd_vms_debug (int level, char *format, ...)
   if (abslvl > min_level)
     return;
 
-  while(--level>0)
-    fprintf(output, " ");
+  while (--level>0)
+    fprintf (output, " ");
   va_start(args, format);
-  vfprintf(output, format, args);
+  vfprintf (output, format, args);
   fflush(output);
   va_end(args);
 
@@ -112,16 +111,15 @@ _bfd_vms_debug (level, format, a1, a2, a3, a4, a5, a6)
   if (level > min_level)
     return;
 
-  while(--level>0)
-    fprintf(output, " ");
-  fprintf(output, format, a1, a2, a3, a4, a5, a6);
+  while (--level>0)
+    fprintf (output, " ");
+  fprintf (output, format, a1, a2, a3, a4, a5, a6);
   fflush(output);
 
   return;
 }
 #endif /* __STDC__ */
 
-
 /* a debug function
    hex dump 'size' bytes starting at 'ptr'  */
 
@@ -220,7 +218,7 @@ _bfd_vms_hash_newfunc (entry, table, string)
 
 void
 _bfd_vms_get_header_values (abfd, buf, type, length)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      unsigned char *buf;
      int *type;
      int *length;
@@ -235,43 +233,41 @@ _bfd_vms_get_header_values (abfd, buf, type, length)
   vms_debug (10, "_bfd_vms_get_header_values type %x, length %x\n", (type?*type:0), (length?*length:0));
 #endif
 
-
   return;
 }
 
-
 /* Get next record from object file to vms_buf
    set PRIV(buf_size) and return it
-  
+
    this is a little tricky since it should be portable.
-  
+
    the openVMS object file has 'variable length' which means that
    read() returns data in chunks of (hopefully) correct and expected
    size. The linker (and other tools on vms) depend on that. Unix doesn't
    know about 'formatted' files, so reading and writing such an object
    file in a unix environment is not trivial.
-  
+
    With the tool 'file' (available on all vms ftp sites), one
    can view and change the attributes of a file. Changing from
    'variable length' to 'fixed length, 512 bytes' reveals the
    record length at the first 2 bytes of every record. The same
    happens during the transfer of object files from vms to unix,
    at least with ucx, dec's implementation of tcp/ip.
-  
+
    The vms format repeats the length at bytes 2 & 3 of every record.
-  
+
    On the first call (file_format == FF_UNKNOWN) we check if
    the first and the third byte pair (!) of the record match.
    If they do it's an object file in an unix environment or with
    wrong attributes (FF_FOREIGN), else we should be in a vms
    environment where read() returns the record size (FF_NATIVE).
-  
+
    reading is always done in 2 steps.
    first just the record header is read and the length extracted
    by get_header_values
    then the read buffer is adjusted and the remaining bytes are
    read in.
-  
+
    all file i/o is always done on even file positions  */
 
 int
@@ -313,22 +309,23 @@ _bfd_vms_get_record (abfd)
 
   switch (PRIV(file_format))
     {
-      case FF_UNKNOWN:
-      case FF_FOREIGN:
-       test_len = 6;                   /* probe 6 bytes */
-       test_start = 2;                 /* where the record starts */
+    case FF_UNKNOWN:
+    case FF_FOREIGN:
+      test_len = 6;                    /* probe 6 bytes */
+      test_start = 2;                  /* where the record starts */
       break;
 
-      case FF_NATIVE:
-       test_len = 4;
-       test_start = 0;
+    case FF_NATIVE:
+      test_len = 4;
+      test_start = 0;
       break;
 
-      case FF_VAX:
-       test_len = 0;
-       test_start = 0;
+    default:
+    case FF_VAX:
+      test_len = 0;
+      test_start = 0;
       break;
-  }
+    }
 
   /* skip odd alignment byte  */
 
@@ -344,7 +341,8 @@ _bfd_vms_get_record (abfd)
   /* read the record header on Alpha.  */
 
   if ((test_len != 0)
-      && (bfd_read (PRIV(vms_buf), 1, test_len, abfd) != test_len))
+      && (bfd_read (PRIV(vms_buf), 1, test_len, abfd)
+         != (bfd_size_type) test_len))
     {
       bfd_set_error (bfd_error_file_truncated);
       return 0;
@@ -419,7 +417,8 @@ _bfd_vms_get_record (abfd)
 #if VMS_DEBUG
       vms_debug (10, "bfd_read remaining %d\n", remaining);
 #endif
-      if (bfd_read (vms_buf + test_len, 1, remaining, abfd) != remaining)
+      if (bfd_read (vms_buf + test_len, 1, remaining, abfd) !=
+         (bfd_size_type) remaining)
        {
          bfd_set_error (bfd_error_file_truncated);
          return 0;
@@ -434,7 +433,6 @@ _bfd_vms_get_record (abfd)
   return PRIV(rec_length);
 }
 
-
 /* get next vms record from file
    update vms_rec and rec_length to new (remaining) values  */
 
@@ -457,6 +455,10 @@ _bfd_vms_next_record (abfd)
        return -1;
     }
 
+  if (!PRIV(vms_rec) || !PRIV(vms_buf)
+      || PRIV(vms_rec) >= (PRIV(vms_buf) + PRIV(buf_size)))
+    return -1;
+
   if (PRIV(is_vax))
     {
       PRIV(rec_type) = *(PRIV(vms_rec));
@@ -478,7 +480,6 @@ _bfd_vms_next_record (abfd)
   return PRIV(rec_type);
 }
 
-
 \f
 /* Copy sized string (string with fixed length) to new allocated area
    size is string length (size of record)  */
@@ -542,7 +543,6 @@ _bfd_vms_push (abfd, val, psect)
   return;
 }
 
-
 /* Pop value and section index  */
 
 uquad
@@ -604,7 +604,6 @@ add_new_contents (abfd, section)
   return newptr;
 }
 
-
 /* Save section data & offset to an vms_section structure
    vms_section_table[] holds the vms_section chain  */
 
@@ -633,7 +632,6 @@ _bfd_save_vms_section (abfd, section, data, offset, count)
   return true;
 }
 
-
 /* Get vms_section pointer to saved contents for section # index  */
 
 vms_section *
@@ -688,7 +686,6 @@ _bfd_vms_output_begin (abfd, rectype, rechead)
   return;
 }
 
-
 /* Set record/subrecord alignment  */
 
 void
@@ -704,7 +701,6 @@ _bfd_vms_output_alignment (abfd, alignto)
   return;
 }
 
-
 /* Prepare for subrecord fields  */
 
 void
@@ -720,7 +716,6 @@ _bfd_vms_output_push (abfd)
   return;
 }
 
-
 /* End of subrecord fields  */
 
 void
@@ -743,7 +738,6 @@ _bfd_vms_output_pop (abfd)
   return;
 }
 
-
 /* Flush unwritten output, ends current record  */
 
 void
@@ -773,7 +767,7 @@ _bfd_vms_output_flush (abfd)
   vms_debug (6, "align: adding %d bytes\n", aligncount);
 #endif
 
-  while(aligncount-- > 0)
+  while (aligncount-- > 0)
     {
       PRIV(output_buf)[real_size++] = 0;
 #if 0
@@ -808,7 +802,6 @@ _bfd_vms_output_flush (abfd)
   return;
 }
 
-
 /* End record output  */
 
 void
@@ -824,7 +817,6 @@ _bfd_vms_output_end (abfd)
   return;
 }
 
-
 /* check remaining buffer size
 
    return what's left.  */
@@ -841,7 +833,6 @@ _bfd_vms_output_check (abfd, size)
   return (MAX_OUTREC_SIZE - (PRIV(output_size) + size + MIN_OUTREC_LUFT));
 }
 
-
 /* Output byte (8 bit) value  */
 
 void
@@ -858,7 +849,6 @@ _bfd_vms_output_byte (abfd, value)
   return;
 }
 
-
 /* Output short (16 bit) value  */
 
 void
@@ -875,7 +865,6 @@ _bfd_vms_output_short (abfd, value)
   return;
 }
 
-
 /* Output long (32 bit) value  */
 
 void
@@ -892,7 +881,6 @@ _bfd_vms_output_long (abfd, value)
   return;
 }
 
-
 /* Output quad (64 bit) value  */
 
 void
@@ -909,7 +897,6 @@ _bfd_vms_output_quad (abfd, value)
   return;
 }
 
-
 /* Output c-string as counted string  */
 
 void
@@ -938,7 +925,6 @@ int len;
   _bfd_vms_output_dump (abfd, (unsigned char *)value, len);
 }
 
-
 /* Output character area  */
 
 void
@@ -960,7 +946,6 @@ _bfd_vms_output_dump (abfd, data, length)
   return;
 }
 
-
 /* Output count bytes of value  */
 
 void
@@ -1008,10 +993,8 @@ _bfd_vms_length_hash_symbol (abfd, in, maxlen)
      const char *in;
      int maxlen;
 {
-  long int init;
   long int result;
   int in_len;
-  char *pnt = 0;
   char *new_name;
   const char *old_name;
   int i;
@@ -1055,7 +1038,7 @@ _bfd_vms_length_hash_symbol (abfd, in, maxlen)
 
   if ((in_len > maxlen)
       && PRIV(flag_hash_long_names))
-    sprintf (out, "_%08x", result);
+    sprintf (out, "_%08lx", result);
   else
     *out = 0;
 
@@ -1071,7 +1054,6 @@ _bfd_vms_length_hash_symbol (abfd, in, maxlen)
   return outbuf;
 }
 
-
 /* Allocate and initialize a new symbol.  */
 
 static asymbol *
@@ -1094,7 +1076,6 @@ new_symbol (abfd, name)
   return symbol;
 }
 
-
 /* Allocate and enter a new private symbol.  */
 
 vms_symbol_entry *
This page took 0.027124 seconds and 4 git commands to generate.