From ea882e87442529ff09a3382b23ab8f3594edc31d Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 27 Mar 2009 11:38:30 +0000 Subject: [PATCH] * 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. --- bfd/ChangeLog | 6 ++++++ bfd/section.c | 10 ++++++++++ 2 files changed, 16 insertions(+) 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; } -- 2.30.2