Source-Changes-HG archive

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

[src/trunk]: src Changes to put the COMPAT_AOUT code into ld.aout_so. Search...



details:   https://anonhg.NetBSD.org/src/rev/2145c9a808a3
branches:  trunk
changeset: 486653:2145c9a808a3
user:      matt <matt%NetBSD.org@localhost>
date:      Sat May 27 06:53:29 2000 +0000

description:
Changes to put the COMPAT_AOUT code into ld.aout_so.  Search <dir> for <lib>
then search /emul/aout/<dir> for <lib>.  To make sure we don't get false
postives on ELF libraries we make the .so is a ZMAGIC dynamic library.

diffstat:

 libexec/ld.aout_so/shlib.c |  41 ++++++++++++++++++++++++++++++++++-------
 sbin/ldconfig/ldconfig.c   |   4 ++--
 2 files changed, 36 insertions(+), 9 deletions(-)

diffs (106 lines):

diff -r 510a9caf7e0d -r 2145c9a808a3 libexec/ld.aout_so/shlib.c
--- a/libexec/ld.aout_so/shlib.c        Sat May 27 06:51:30 2000 +0000
+++ b/libexec/ld.aout_so/shlib.c        Sat May 27 06:53:29 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shlib.c,v 1.17 1999/11/29 08:27:07 itohy Exp $ */
+/*     $NetBSD: shlib.c,v 1.18 2000/05/27 06:53:30 matt 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_aout.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) {
diff -r 510a9caf7e0d -r 2145c9a808a3 sbin/ldconfig/ldconfig.c
--- a/sbin/ldconfig/ldconfig.c  Sat May 27 06:51:30 2000 +0000
+++ b/sbin/ldconfig/ldconfig.c  Sat May 27 06:53:29 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ldconfig.c,v 1.27 1999/07/16 22:23:29 christos Exp $   */
+/*     $NetBSD: ldconfig.c,v 1.28 2000/05/27 06:53:29 matt Exp $       */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -174,7 +174,7 @@
        }
 
        while ((line = fgetln(conf, &len)) != NULL) {
-               if (*line == '#' || *line == '\n')
+               if (*line != '/')
                        continue;
 
                if (line[len-1] == '\n') {



Home | Main Index | Thread Index | Old Index