From: Nick Clifton Date: Fri, 27 Mar 2009 11:38:30 +0000 (+0000) Subject: * section.c (bfd_get_section_contents): Detect and handle the case X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ea882e87442529ff09a3382b23ab8f3594edc31d;p=binutils-gdb.git * section.c (bfd_get_section_contents): Detect and handle the case where a section has the SEC_IN_MEMORY flag set but no actual contents allocated. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 11a0acbbf83..1fcef7b29ab 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2009-03-27 Nick Clifton + + * section.c (bfd_get_section_contents): Detect and handle the case + where a section has the SEC_IN_MEMORY flag set but no actual + contents allocated. + 2009-03-26 Alan Modra PR 6494 diff --git a/bfd/section.c b/bfd/section.c index 5a335a62909..dc8225f39d3 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -1436,6 +1436,16 @@ bfd_get_section_contents (bfd *abfd, if ((section->flags & SEC_IN_MEMORY) != 0) { + if (section->contents == NULL) + { + /* This can happen because of errors earlier on in the linking process. + We do not want to seg-fault here, so clear the flag and return an + error code. */ + section->flags &= ~ SEC_IN_MEMORY; + bfd_set_error (bfd_error_invalid_operation); + return FALSE; + } + memcpy (location, section->contents + offset, (size_t) count); return TRUE; }