* PR17910 sym string offset check
@ 2023-03-21 22:47 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-03-21 22:47 UTC (permalink / raw)
To: binutils
As far as I can see the only place that sets obj_coff_strings without
setting obj_coff_strings_len is pe_ILF_build_a_bfd. Fix that and we
can simplify the sym string offset check. This is just a tidy.
pe_ILF_build_a_bfd doesn't create bad symbols and
_bfd_coff_read_string_table will always result in non-zero
obj_coff_strings_len when obj_coff_strings is non-NULL.
This patch came about because I was trying to track down an
uninitialised memory access and wondered if in some cases
_bfd_coff_internal_syment_name was allowing wild string offsets by
omitting the check. It turns out it wasn't, but this way someone
looking at the code won't need to check further.
PR 17910
* coffgen.c (_bfd_coff_internal_syment_name): Always sanity
check sym string offset.
* peicode.h (pe_ILF_build_a_bfd): Set obj_coff_strings_len.
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index f21cf2ca523..774edf76f24 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -443,10 +443,7 @@ _bfd_coff_internal_syment_name (bfd *abfd,
if (strings == NULL)
return NULL;
}
- /* PR 17910: Only check for string overflow if the length has been set.
- Some DLLs, eg those produced by Visual Studio, may not set the length field. */
- if (obj_coff_strings_len (abfd) > 0
- && sym->_n._n_n._n_offset >= obj_coff_strings_len (abfd))
+ if (sym->_n._n_n._n_offset >= obj_coff_strings_len (abfd))
return NULL;
return strings + sym->_n._n_n._n_offset;
}
diff --git a/bfd/peicode.h b/bfd/peicode.h
index b7b4f4abbb9..f1f3ce81533 100644
--- a/bfd/peicode.h
+++ b/bfd/peicode.h
@@ -1147,6 +1147,7 @@ pe_ILF_build_a_bfd (bfd * abfd,
obj_conv_table_size (abfd) = vars.sym_index;
obj_coff_strings (abfd) = vars.string_table;
+ obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
obj_coff_keep_strings (abfd) = true;
return true;
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-21 22:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 22:47 PR17910 sym string offset check Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).