This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: fail gracefully on program without any loadable sections
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Roland McGrath <roland at redhat dot com>
- Cc: libc-alpha at sources dot redhat dot com
- Date: 14 Mar 2003 00:37:38 -0300
- Subject: Re: fail gracefully on program without any loadable sections
- Organization: GCC Team, Red Hat
- References: <200303140325.h2E3PM315477@magilla.sf.frob.com>
On Mar 14, 2003, Roland McGrath <roland at redhat dot com> wrote:
> I would like to have a test case for this. How did you make the file you
> tried to load that has this problem?
I don't recall whether it was a bug in the compiler, the linker or in
glibc data structures that triggered this particular condition, but
it's definitely not something that you'd find in real life. I'm ok
with leaving it out, I just thought it would be nice to produce a
reasonable error message in this case, otherwise we'll likely just
crash in the next few instructions (note that we index loadcmds on
nloadcmds - 1, so if nloadcmds is zero, you get garbage).
Anyway, here's the patch, with ChangeLog adjusted as requested.
Index: ChangeLog
2003-03-13 Alexandre Oliva <aoliva at redhat dot com>
* elf/dl-load.c: Lose if there are no loadable sections.
Index: elf/dl-load.c
===================================================================
RCS file: /cvs/glibc/libc/elf/dl-load.c,v
retrieving revision 1.220
diff -u -p -r1.220 dl-load.c
--- elf/dl-load.c 4 Mar 2003 00:08:51 -0000 1.220
+++ elf/dl-load.c 14 Mar 2003 01:00:15 -0000
@@ -1031,6 +1031,12 @@ cannot allocate TLS data structures for
/* Now process the load commands and map segments into memory. */
c = loadcmds;
+ if (nloadcmds == 0)
+ {
+ errstring = N_("no loadable sections");
+ goto call_lose;
+ }
+
/* Length of the sections to be loaded. */
maplength = loadcmds[nloadcmds - 1].allocend - c->mapstart;
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist Professional serial bug killer