readlink in /proc w/ overlong path
-----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-----