All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ulrich Drepper <drepper@redhat.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: readlink in /proc w/ overlong path
Date: Sat, 29 Mar 2003 22:21:16 -0800	[thread overview]
Message-ID: <3E868CDC.9030002@redhat.com> (raw)

-----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-----


                 reply	other threads:[~2003-03-30  6:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3E868CDC.9030002@redhat.com \
    --to=drepper@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.