/* vms-misc.c -- BFD back-end for VMS/VAX (openVMS/VAX) and
EVAX (openVMS/Alpha) files.
- Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 1996-2020 Free Software Foundation, Inc.
Miscellaneous functions.
#endif
\f
-/* Copy sized string (string with fixed size) to new allocated area
- size is string size (size of record) */
+/* Copy sized string (string with fixed size) to new allocated area.
+ Size is string size (size of record). */
char *
-_bfd_vms_save_sized_string (unsigned char *str, int size)
+_bfd_vms_save_sized_string (bfd *abfd, unsigned char *str, size_t size)
{
- char *newstr = bfd_malloc ((bfd_size_type) size + 1);
+ char *newstr;
+ if (size == (size_t) -1)
+ {
+ bfd_set_error (bfd_error_no_memory);
+ return NULL;
+ }
+ newstr = bfd_alloc (abfd, size + 1);
if (newstr == NULL)
return NULL;
- memcpy (newstr, (char *) str, (size_t) size);
+ memcpy (newstr, str, size);
newstr[size] = 0;
return newstr;
}
-/* Copy counted string (string with size at first byte) to new allocated area
- ptr points to size byte on entry */
+/* Copy counted string (string with size at first byte) to new allocated area.
+ PTR points to size byte on entry. */
char *
-_bfd_vms_save_counted_string (unsigned char *ptr)
+_bfd_vms_save_counted_string (bfd *abfd, unsigned char *ptr, size_t maxlen)
{
- int len = *ptr++;
+ unsigned int len = *ptr++;
- return _bfd_vms_save_sized_string (ptr, len);
+ if (len > maxlen)
+ return NULL;
+ return _bfd_vms_save_sized_string (abfd, ptr, len);
}
\f
/* Object output routines. */
/* Put length to buffer. */
bfd_putl16 ((bfd_vma) (recwr->size - recwr->subrec_offset),
- recwr->buf + recwr->subrec_offset + 2);
+ recwr->buf + recwr->subrec_offset + 2);
/* Close the subrecord. */
recwr->subrec_offset = 0;
len = strlen (value);
if (len == 0)
{
- (*_bfd_error_handler) (_("_bfd_vms_output_counted called with zero bytes"));
+ _bfd_error_handler (_("_bfd_vms_output_counted called with zero bytes"));
return;
}
if (len > 255)
{
- (*_bfd_error_handler) (_("_bfd_vms_output_counted called with too many bytes"));
+ _bfd_error_handler (_("_bfd_vms_output_counted called with too many bytes"));
return;
}
_bfd_vms_output_byte (recwr, (unsigned int) len & 0xff);
for (fptr = fname; *fptr != 0; fptr++)
{
if (*fptr == ';' || (fptr - fname) >= 31)
- {
- *fptr = 0;
- break;
- }
+ {
+ *fptr = 0;
+ break;
+ }
if (upcase)
- *fptr = TOUPPER (*fptr);
+ *fptr = TOUPPER (*fptr);
}
return fname;
}