Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/libexec/ld.aout_so Pull up revision 1.18 (via patch, re...



details:   https://anonhg.NetBSD.org/src/rev/84c74a094925
branches:  netbsd-1-4
changeset: 470632:84c74a094925
user:      he <he%NetBSD.org@localhost>
date:      Thu Jun 01 17:46:23 2000 +0000

description:
Pull up revision 1.18 (via patch, requested by matt):
  Enable searching for libraries under /emul/aout, and make sure
  that ELF libraries are not erroneously accepted.

diffstat:

 libexec/ld.aout_so/shlib.c |  41 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 34 insertions(+), 7 deletions(-)

diffs (88 lines):

diff -r 05cf991f9a51 -r 84c74a094925 libexec/ld.aout_so/shlib.c
--- a/libexec/ld.aout_so/shlib.c        Thu Jun 01 17:43:42 2000 +0000
+++ b/libexec/ld.aout_so/shlib.c        Thu Jun 01 17:46:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shlib.c,v 1.16 1998/12/15 23:16:14 pk Exp $    */
+/*     $NetBSD: shlib.c,v 1.16.2.1 2000/06/01 17:46:23 he Exp $        */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -50,9 +50,11 @@
 #include <dirent.h>
 #include <err.h>
 #include <fcntl.h>
+#include <a.out.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <paths.h>
 #include <link.h>
 
 #include "shlib.h"
@@ -79,10 +81,14 @@
 add_search_dir(name)
        char    *name;
 {
-       n_search_dirs++;
+       n_search_dirs += 2;
        search_dirs = (char **)
                xrealloc(search_dirs, n_search_dirs * sizeof search_dirs[0]);
-       search_dirs[n_search_dirs - 1] = strdup(name);
+       search_dirs[n_search_dirs - 2] = strdup(name);
+       search_dirs[n_search_dirs - 1] =
+           xmalloc(sizeof(_PATH_EMUL_AOUT) + strlen(name));
+       strcpy(search_dirs[n_search_dirs - 1], _PATH_EMUL_AOUT);
+       strcat(search_dirs[n_search_dirs - 1], name);
 }
 
 void
@@ -95,10 +101,11 @@
                if (strcmp(search_dirs[n], name))
                        continue;
                free(search_dirs[n]);
-               if (n < (n_search_dirs - 1))
-                       bcopy(&search_dirs[n+1], &search_dirs[n],
-                             (n_search_dirs - n - 1) * sizeof search_dirs[0]);
-               n_search_dirs--;
+               free(search_dirs[n+1]);
+               if (n < (n_search_dirs - 2))
+                       bcopy(&search_dirs[n+2], &search_dirs[n],
+                             (n_search_dirs - n - 2) * sizeof search_dirs[0]);
+               n_search_dirs -= 2;
        }
 }
 
@@ -255,6 +262,9 @@
 
                while ((dp = readdir(dd)) != NULL) {
                        int     n;
+                       struct exec ex;
+                       char *xpath;
+                       FILE *fp;
 
                        if (do_dot_a && path == NULL &&
                                        dp->d_namlen == len + 2 &&
@@ -282,6 +292,23 @@
                                found_dot_a = 0;
                        }
 
+                       /* verify the library is a.out */
+                       xpath = concat(search_dirs[i], "/", dp->d_name);
+                       fp = fopen(xpath, "r");
+                       free(xpath);
+                       if (fp == NULL) {
+                               continue;
+                       }
+                       if (sizeof(ex) != fread(&ex, 1, sizeof(ex), fp)) {
+                               fclose(fp);
+                               continue;
+                       }
+                       fclose(fp);
+                       if (N_GETMAGIC(ex) != ZMAGIC
+                           || (N_GETFLAG(ex) & EX_DYNAMIC) == 0) {
+                               continue;
+                       }
+
                        if (major == -1 && minor == -1) {
                                goto compare_version;
                        } else if (major != -1 && minor == -1) {



Home | Main Index | Thread Index | Old Index