Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/compat/gen Restore binary compatibility with netbsd...



details:   https://anonhg.NetBSD.org/src/rev/24591738bd21
branches:  trunk
changeset: 773591:24591738bd21
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 08 03:24:30 2012 +0000

description:
Restore binary compatibility with netbsd-1.x for readdir(3). Tested with
a shark tcsh dynamic binary:

    tcsh: ELF 32-bit LSB executable, ARM, version 1, dynamically linked \
        (uses shared libs), for NetBSD, not stripped
    -rwxr-xr-x  1 root  wheel  994170 Jun 24  2004 /bin/tcsh

This would infinite loop on ls-F /dev

diffstat:

 lib/libc/compat/gen/compat_readdir.c |  46 +++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 3 deletions(-)

diffs (62 lines):

diff -r 7874acee8e91 -r 24591738bd21 lib/libc/compat/gen/compat_readdir.c
--- a/lib/libc/compat/gen/compat_readdir.c      Tue Feb 07 23:15:33 2012 +0000
+++ b/lib/libc/compat/gen/compat_readdir.c      Wed Feb 08 03:24:30 2012 +0000
@@ -1,8 +1,12 @@
-/*     $NetBSD: compat_readdir.c,v 1.1 2005/09/13 01:44:09 christos Exp $      */
+/*     $NetBSD: compat_readdir.c,v 1.2 2012/02/08 03:24:30 christos Exp $      */
 
 #define __LIBC12_SOURCE__
 #include "namespace.h"
+#include <sys/param.h>
 #include <dirent.h>
+#include <errno.h>
+#include <string.h>
+#include <limits.h>
 #include <compat/include/dirent.h>
 
 #ifdef __weak_alias
@@ -17,6 +21,42 @@
     "warning: reference to compatibility readdir_r(); include <dirent.h> for correct reference")
 #endif
 
-#define dirent dirent12
+static struct dirent12 *
+direnttodirent12(struct dirent12 *d12, const struct dirent *d)
+{
+       if (d == NULL)
+               return NULL;
+
+       if (d->d_fileno > UINT_MAX || d->d_namlen >= sizeof(d12->d_name)) {
+               errno = ERANGE;
+               return NULL;
+       }
+       d12->d_fileno = (uint32_t)d->d_fileno;
+       d12->d_reclen = (uint16_t)d->d_reclen;
+       d12->d_namlen = (uint8_t)MIN(d->d_namlen, sizeof(d->d_name) - 1);
+       d12->d_type = (uint8_t)d->d_type;
+       memcpy(d12->d_name, d->d_name, d12->d_namlen);
+       d12->d_name[d12->d_namlen] = '\0';
+       return d12;
+}
 
-#include "gen/readdir.c"
+struct dirent12 *
+readdir(DIR *dirp)
+{
+       static struct dirent12 d12;
+       return direnttodirent12(&d12, __readdir30(dirp));
+}
+
+int
+readdir_r(DIR *dirp, struct dirent12 *entry, struct dirent12 **result)
+{
+       int error;
+       struct dirent e, *ep;
+
+       if ((error = __readdir_r30(dirp, &e, &ep)) != 0)
+               return error;
+
+       *result = entry;
+       (void)direnttodirent12(entry, &e);
+       return 0;
+}



Home | Main Index | Thread Index | Old Index