1 - namei ignores non-directory components instead of saying "Not a directory"
2 - namei enforces symlink limits inconsistently
4 --- util-linux-2.13-pre7/misc-utils/namei.1.nodir 2006-12-15 10:58:38.000000000 +0100
5 +++ util-linux-2.13-pre7/misc-utils/namei.1 2006-12-15 10:58:51.000000000 +0100
7 Roger Southwick (rogers@amadeus.wr.tek.com)
12 -will follow an infinite loop of symbolic links forever. To escape, use
16 --- util-linux-2.13-pre7/misc-utils/namei.c.nodir 2006-12-14 21:38:41.000000000 +0100
17 +++ util-linux-2.13-pre7/misc-utils/namei.c 2006-12-15 10:58:31.000000000 +0100
19 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
20 - added Native Language Support
22 +2006-12-15 Karel Zak <kzak@redhat.com>
23 +- fixed logic; don't follow the path if a component is not directory
24 +- fixed infinite loop of symbolic links; stack size is very limited
26 -------------------------------------------------------------*/
32 static char *pperm(unsigned short);
33 -static void namei(char *, int);
34 +static void namei(char *, int, mode_t *);
35 static void usage(void);
41 for(; optind < argc; optind++){
42 + mode_t lastmode = 0;
43 (void)printf("f: %s\n", argv[optind]);
45 - namei(argv[optind], 0);
46 + namei(argv[optind], 0, &lastmode);
48 if(chdir(curdir) == -1){
51 #define NODEV (dev_t)(-1)
57 -namei(char *file, int lev) {
58 +namei(char *file, int lev, mode_t *lastmode) {
60 char buf[BUFSIZ], sym[BUFSIZ];
63 * See if the file has a leading /, and if so cd to root
67 + if(file && *file == '/'){
72 (void)printf(" d /\n");
76 + for(; file && *file;){
78 if (strlen(file) >= BUFSIZ) {
79 fprintf(stderr,_("namei: buf overflow\n"));
81 for(i = 0; i < lev; i++)
86 + * Previous element in the path wasn't directory, it means
87 + * we cannot walk on *path* and check the actual element by lstat(), because
88 + * there could be a component with same name. Try:
91 + * $ namei a/b <-- "a" is not directory so namei shouldn't check for "b"
93 + if (*lastmode && S_ISDIR(*lastmode)==0 && S_ISLNK(*lastmode)==0){
94 + (void)printf(" ? %s - %s (%d)\n", buf, strerror(ENOENT), ENOENT);
99 * See what type of critter this file is
105 + *lastmode = stb.st_mode;
107 switch(stb.st_mode & S_IFMT){
111 * Sigh, another symlink. Read its contents and
116 if(readlink(buf, sym, BUFSIZ) == -1){
117 (void)printf(_(" ? problems reading symlink %s - %s (%d)\n"), buf, ERR);
118 @@ -255,11 +277,12 @@
120 if(symcount > 0 && symcount++ > MAXSYMLINKS){
121 (void)printf(_(" *** EXCEEDED UNIX LIMIT OF SYMLINKS ***\n"));
125 - namei(sym, lev + 1);
126 + namei(sym, lev + 1, lastmode);
128 + if (symcount > MAXSYMLINKS)