]> git.pld-linux.org Git - packages/util-linux.git/blob - util-linux-namei-logic.patch
- uniformized configs to use system-auth where possible
[packages/util-linux.git] / util-linux-namei-logic.patch
1 - namei ignores non-directory components instead of saying "Not a directory"
2 - namei enforces symlink limits inconsistently
3
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
6 @@ -52,9 +52,5 @@
7  Roger Southwick  (rogers@amadeus.wr.tek.com)
8  .SH BUGS
9  To be discovered.
10 -.SH CAVEATS
11 -.I Namei
12 -will follow an infinite loop of symbolic links forever.  To escape, use
13 -SIGINT (usually ^C).
14  .SH "SEE ALSO"
15  ls(1), stat(1)
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
18 @@ -42,6 +42,10 @@
19  1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
20  - added Native Language Support
21  
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
25 +
26  -------------------------------------------------------------*/
27  
28  #include <stdio.h>
29 @@ -66,7 +70,7 @@
30  #endif
31  
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);
36  
37  int
38 @@ -107,9 +111,10 @@
39  
40  
41      for(; optind < argc; optind++){
42 +       mode_t lastmode = 0;
43         (void)printf("f: %s\n", argv[optind]);
44         symcount = 1;
45 -       namei(argv[optind], 0);
46 +       namei(argv[optind], 0, &lastmode);
47  
48         if(chdir(curdir) == -1){
49             (void)fprintf(stderr,
50 @@ -131,8 +136,10 @@
51  #define NODEV          (dev_t)(-1)
52  #endif
53  
54 +int kzak;
55 +
56  static void
57 -namei(char *file, int lev) {
58 +namei(char *file, int lev, mode_t *lastmode) {
59      char *cp;
60      char buf[BUFSIZ], sym[BUFSIZ];
61      struct stat stb;
62 @@ -143,7 +150,7 @@
63       * See if the file has a leading /, and if so cd to root
64       */
65      
66 -    if(*file == '/'){
67 +    if(file && *file == '/'){
68         while(*file == '/')
69             file++;
70         
71 @@ -166,7 +173,7 @@
72             (void)printf(" d /\n");
73      }
74  
75 -    for(;;){
76 +    for(; file && *file;){
77  
78         if (strlen(file) >= BUFSIZ) {
79                 fprintf(stderr,_("namei: buf overflow\n"));
80 @@ -198,6 +205,20 @@
81         for(i = 0; i < lev; i++)
82             (void)printf("  ");
83  
84 +
85 +       /*
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:
89 +        *
90 +        * $ touch a b
91 +        * $ namei a/b    <-- "a" is not directory so namei shouldn't check for "b"
92 +        */
93 +       if (*lastmode && S_ISDIR(*lastmode)==0 && S_ISLNK(*lastmode)==0){
94 +           (void)printf(" ? %s - %s (%d)\n", buf, strerror(ENOENT), ENOENT);
95 +           return;
96 +       }
97 +
98         /*
99          * See what type of critter this file is
100          */
101 @@ -207,6 +228,8 @@
102             return;
103         }
104  
105 +       *lastmode = stb.st_mode;
106 +
107         switch(stb.st_mode & S_IFMT){
108             case S_IFDIR:
109  
110 @@ -241,7 +264,6 @@
111                  * Sigh, another symlink.  Read its contents and
112                  * call namei()
113                  */
114 -               
115                 bzero(sym, BUFSIZ);
116                 if(readlink(buf, sym, BUFSIZ) == -1){
117                     (void)printf(_(" ? problems reading symlink %s - %s (%d)\n"), buf, ERR);
118 @@ -255,11 +277,12 @@
119  
120                 if(symcount > 0 && symcount++ > MAXSYMLINKS){
121                     (void)printf(_("  *** EXCEEDED UNIX LIMIT OF SYMLINKS ***\n"));
122 -                   symcount = -1;
123                 } else {
124                     (void)printf("\n");
125 -                   namei(sym, lev + 1);
126 +                   namei(sym, lev + 1, lastmode);
127                 }
128 +               if (symcount > MAXSYMLINKS)
129 +                   return;
130                 break;
131  
132             case S_IFCHR:
This page took 0.358175 seconds and 3 git commands to generate.