X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=bfd%2Fvms-misc.c;h=bc422895bd02a2369ab9dec30ad08fe55c089c32;hb=aa739c59d3db95d1709b0417cdf7d082bfdea911;hp=40c6cc263fa7abbf5eda33f651f8c7482e1e077e;hpb=2571583aed598dd3f9651b53434e5f177a0e3cf7;p=binutils-gdb.git diff --git a/bfd/vms-misc.c b/bfd/vms-misc.c index 40c6cc263fa..bc422895bd0 100644 --- a/bfd/vms-misc.c +++ b/bfd/vms-misc.c @@ -1,6 +1,6 @@ /* vms-misc.c -- BFD back-end for VMS/VAX (openVMS/VAX) and EVAX (openVMS/Alpha) files. - Copyright (C) 1996-2017 Free Software Foundation, Inc. + Copyright (C) 1996-2019 Free Software Foundation, Inc. Miscellaneous functions. @@ -135,11 +135,11 @@ _bfd_hexdump (int level, unsigned char *ptr, int size, int offset) #endif -/* 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 (unsigned char *str, unsigned int size) { char *newstr = bfd_malloc ((bfd_size_type) size + 1); @@ -151,14 +151,16 @@ _bfd_vms_save_sized_string (unsigned char *str, int size) 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 (unsigned char *ptr, unsigned int maxlen) { - int len = *ptr++; + unsigned int len = *ptr++; + if (len > maxlen) + return NULL; return _bfd_vms_save_sized_string (ptr, len); } @@ -250,7 +252,7 @@ _bfd_vms_output_end_subrec (struct vms_rec_wr *recwr) /* 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; @@ -514,12 +516,12 @@ vms_get_module_name (const char *filename, bfd_boolean upcase) 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; }