diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 11a0acbbf8..1fcef7b29a 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 5a335a6290..dc8225f39d 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; }