This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fail gracefully on program without any loadable sections

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
Red Hat GCC Developer                 aoliva at {redhat dot com,}
CS PhD student at IC-Unicamp        oliva at {lsd dot ic dot unicamp dot br,}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]