* readlink in /proc w/ overlong path
@ 2003-03-30 6:21 Ulrich Drepper
0 siblings, 0 replies; only message in thread
From: Ulrich Drepper @ 2003-03-30 6:21 UTC (permalink / raw)
To: Linux Kernel
-----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-----
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-03-30 6:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-30 6:21 readlink in /proc w/ overlong path Ulrich Drepper
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox