GNU Binutils with patches for OS216
Revisión | 07d22f648e56d7276fa7a4a73438005448c406fb (tree) |
---|---|
Tiempo | 2020-06-29 09:39:14 |
Autor | Alan Modra <amodra@gmai...> |
Commiter | Alan Modra |
asan: _bfd_pei_slurp_codeview_record use of uninit value
Fixes some seriously careless code. bfd_bread return value is
(bfd_size_type)-1 on error. "if (bfd_bread (...) < 4)" does not check
for an error since bfd_size_type is unsigned. In any case, I think we
should be reading and checking the requested length.
* peXXigen.c (_bfd_XXi_slurp_codeview_record): Properly check
return value of bfd_bread. Don't read more than requested length.
Sanity check length. Properly terminate file name.
@@ -1,5 +1,11 @@ | ||
1 | 1 | 2020-06-29 Alan Modra <amodra@gmail.com> |
2 | 2 | |
3 | + * peXXigen.c (_bfd_XXi_slurp_codeview_record): Properly check | |
4 | + return value of bfd_bread. Don't read more than requested length. | |
5 | + Sanity check length. Properly terminate file name. | |
6 | + | |
7 | +2020-06-29 Alan Modra <amodra@gmail.com> | |
8 | + | |
3 | 9 | * arc-got.h: Use C style comments. |
4 | 10 | * coff-z80.c: Likewise. |
5 | 11 | * elf32-csky.c: Likewise. |
@@ -1147,15 +1147,21 @@ CODEVIEW_INFO * | ||
1147 | 1147 | _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length, CODEVIEW_INFO *cvinfo) |
1148 | 1148 | { |
1149 | 1149 | char buffer[256+1]; |
1150 | + bfd_size_type nread; | |
1150 | 1151 | |
1151 | 1152 | if (bfd_seek (abfd, where, SEEK_SET) != 0) |
1152 | 1153 | return NULL; |
1153 | 1154 | |
1154 | - if (bfd_bread (buffer, 256, abfd) < 4) | |
1155 | + if (length <= sizeof (CV_INFO_PDB70) && length <= sizeof (CV_INFO_PDB20)) | |
1156 | + return NULL; | |
1157 | + if (length > 256) | |
1158 | + length = 256; | |
1159 | + nread = bfd_bread (buffer, length, abfd); | |
1160 | + if (length != nread) | |
1155 | 1161 | return NULL; |
1156 | 1162 | |
1157 | 1163 | /* Ensure null termination of filename. */ |
1158 | - buffer[256] = '\0'; | |
1164 | + memset (buffer + nread, 0, sizeof (buffer) - nread); | |
1159 | 1165 | |
1160 | 1166 | cvinfo->CVSignature = H_GET_32 (abfd, buffer); |
1161 | 1167 | cvinfo->Age = 0; |