readlink in /proc w/ overlong path

From: Ulrich Drepper (drepper@redhat.com)
Date: Sun Mar 30 2003 - 01:21:16 EST


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Trying to read the overlong target of a /proc/*/fd/N file descriptor
leads with the current BK kernel to a segfault in the kernel. This is
on x86 but I have no doubt it's a generaic error. The following the
program illustrates the problem.

#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
int
main (void)
{
  const char s[] =
    "test_____________________________________________________________";
  int i;
  for (i = 0; i < 100; ++i)
    {
      mkdir (s, 0777);
      chdir (s);
    }
  int fd = open ("aaa", O_RDWR | O_CREAT);
  write (fd, "a", 1);
  char buf[200];
  sprintf (buf, "/proc/self/fd/%d", fd);
#define N 200000
  char *buf2 = (char *) malloc (N);
  if (buf2 == NULL)
    error (EXIT_FAILURE, errno, "failed to get memory");
  int n = readlink (buf, buf2, sizeof (buf2));
  if (n < 0 || n > N)
    printf ("readlink returned %d\n", n);
  else
    {
      buf2[n] = '\0';
      printf ("n = %d, %s\n", n, buf2);
    }
  return 0;
}

- --
- --------------. ,-. 444 Castro Street
Ulrich Drepper \ ,-----------------' \ Mountain View, CA 94041 USA
Red Hat `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+hozc2ijCOnn/RHQRArauAJ980Mp4qO8bNQGEVilMFaG3c7Td5ACfTG1q
Rid/4i37aESW5H4U7K7dk5k=
=oyl+
-----END PGP SIGNATURE-----

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Mar 31 2003 - 22:00:35 EST