Subject: Re: CVS commit: basesrc/libexec/ld.elf_so
To: enami tsugutomo <enami@sm.sony.co.jp>
From: Bang Jun-Young <junyoung@netbsd.org>
List: source-changes
Date: 11/22/2002 13:21:21
On Fri, Nov 22, 2002 at 10:17:43AM +0900, enami tsugutomo wrote:
> Bang Jun-Young <junyoung@netbsd.org> writes:
> 
> > Module Name:	basesrc
> > Committed By:	junyoung
> > Date:		Thu Nov 21 19:09:57 UTC 2002
> > 
> > Modified Files:
> > 	basesrc/libexec/ld.elf_so: reloc.c
> > 
> > Log Message:
> > Simplify code a bit.
> > 
> > 
> > To generate a diff of this commit:
> > cvs rdiff -r1.74 -r1.75 basesrc/libexec/ld.elf_so/reloc.c
> 
> Your change makes all errors except the last error are ignored.

No, the old code also had the same bug. When a call is returned with
a value less than 0, _rtld_relocate_objects() should immediately
return with a value indicating an error (-1). As you see below, what's
done is just to set ok to 0.

Index: reloc.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/reloc.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- reloc.c	2002/09/26 20:42:10	1.74
+++ reloc.c	2002/11/21 19:09:56	1.75
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.74 2002/09/26 20:42:10 mycroft Exp $	 */
+/*	$NetBSD: reloc.c,v 1.75 2002/11/21 19:09:56 junyoung Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -153,7 +153,7 @@
 	bool bind_now;
 {
 	Obj_Entry *obj;
-	int ok = 1;
+	int res;
 
 	for (obj = first; obj != NULL; obj = obj->next) {
 		if (obj->nbuckets == 0 || obj->nchains == 0 ||
@@ -183,8 +183,7 @@
 			}
 		}
 		dbg(("doing non-PLT relocations"));
-		if (_rtld_relocate_nonplt_objects(obj) < 0)
-			ok = 0;
+		res = _rtld_relocate_nonplt_objects(obj);
 		if (obj->textrel) {	/* Re-protected the text segment. */
 			if (mprotect(obj->mapbase, obj->textsize,
 				     PROT_READ | PROT_EXEC) == -1) {
@@ -194,14 +193,12 @@
 			}
 		}
 		dbg(("doing lazy PLT binding"));
-		if (_rtld_relocate_plt_lazy(obj) < 0)
-			ok = 0;
+		res = _rtld_relocate_plt_lazy(obj);
 #if defined(__i386__)
 		if (bind_now)
-			if (_rtld_relocate_plt_objects(obj) < 0)
-				ok = 0;
+			res = _rtld_relocate_plt_objects(obj);
 #endif
-		if (!ok)
+		if (res < 0)
 			return -1;
 
I'll fix the code so it does the right thing on failure.

Jun-Young

-- 
Bang Jun-Young <junyoung@netbsd.org>