- fix #217240 - namei ignores non-directory components instead of saying

"Not a directory"
- fix #217241 - namei enforces symlink limits inconsistently
- Resolves: rhbz#217240 rhbz#217241
This commit is contained in:
kzak 2006-12-15 17:05:55 +00:00
parent e593a77fd1
commit f17b9c0d25
4 changed files with 143 additions and 6 deletions

View File

@ -8,8 +8,8 @@
+Although Linux includes support for rawio, it is now a deprecated interface. If +Although Linux includes support for rawio, it is now a deprecated interface. If
+your application performs device access using this interface, Red Hat +your application performs device access using this interface, Red Hat
+encourages you to modify your application to open the block device with the +encourages you to modify your application to open the block device with the
+O_DIRECT flag. The rawio interface will exist for the life of Red Hat +O_DIRECT flag. The rawio interface is a candidate for removal from future releases.
+Enterprise Linux 4, but is a candidate for removal from future releases. +
.SH DESCRIPTION .SH DESCRIPTION
.B raw .B raw
is used to bind a Linux raw character device to a block device. Any is used to bind a Linux raw character device to a block device. Any

View File

@ -79,11 +79,11 @@
+ if (verbose) + if (verbose)
+ printf(_("mount: translated %s '%s' to '%s'\n"), + printf(_("mount: translated %s '%s' to '%s'\n"),
+ optname, data, (char *) raw); + optname, data, (char *) raw);
+ // TODO 2.6.19: context options with commans are unsupported by kernel now ;-( +
+ bufsz = strlen(optname) + strlen(raw) + 2; // bufsz = strlen(optname) + strlen(raw) + 4; /* 4 is \0, '=' and 2x '"' */ + bufsz = strlen(optname) + strlen(raw) + 4; /* 4 is \0, '=' and 2x '"' */
+ buf = xmalloc(bufsz); + buf = xmalloc(bufsz);
+ +
+ snprintf(buf, bufsz, "%s=%s", optname, (char *) raw); // snprintf(buf, bufsz, "%s=\"%s\"", optname, (char *) raw); + snprintf(buf, bufsz, "%s=\"%s\"", optname, (char *) raw);
+ freecon(raw); + freecon(raw);
+ +
+ if ((*len -= bufsz-1) > 0) + if ((*len -= bufsz-1) > 0)

View File

@ -0,0 +1,129 @@
--- util-linux-2.13-pre7/misc-utils/namei.1.nodir 2006-12-15 10:58:38.000000000 +0100
+++ util-linux-2.13-pre7/misc-utils/namei.1 2006-12-15 10:58:51.000000000 +0100
@@ -52,9 +52,5 @@
Roger Southwick (rogers@amadeus.wr.tek.com)
.SH BUGS
To be discovered.
-.SH CAVEATS
-.I Namei
-will follow an infinite loop of symbolic links forever. To escape, use
-SIGINT (usually ^C).
.SH "SEE ALSO"
ls(1), stat(1)
--- util-linux-2.13-pre7/misc-utils/namei.c.nodir 2006-12-14 21:38:41.000000000 +0100
+++ util-linux-2.13-pre7/misc-utils/namei.c 2006-12-15 10:58:31.000000000 +0100
@@ -42,6 +42,10 @@
1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
+2006-12-15 Karel Zak <kzak@redhat.com>
+- fixed logic; don't follow the path if a component is not directory
+- fixed infinite loop of symbolic links; stack size is very limited
+
-------------------------------------------------------------*/
#include <stdio.h>
@@ -66,7 +70,7 @@
#endif
static char *pperm(unsigned short);
-static void namei(char *, int);
+static void namei(char *, int, mode_t *);
static void usage(void);
int
@@ -107,9 +111,10 @@
for(; optind < argc; optind++){
+ mode_t lastmode = 0;
(void)printf("f: %s\n", argv[optind]);
symcount = 1;
- namei(argv[optind], 0);
+ namei(argv[optind], 0, &lastmode);
if(chdir(curdir) == -1){
(void)fprintf(stderr,
@@ -131,8 +136,10 @@
#define NODEV (dev_t)(-1)
#endif
+int kzak;
+
static void
-namei(char *file, int lev) {
+namei(char *file, int lev, mode_t *lastmode) {
char *cp;
char buf[BUFSIZ], sym[BUFSIZ];
struct stat stb;
@@ -143,7 +150,7 @@
* See if the file has a leading /, and if so cd to root
*/
- if(*file == '/'){
+ if(file && *file == '/'){
while(*file == '/')
file++;
@@ -166,7 +173,7 @@
(void)printf(" d /\n");
}
- for(;;){
+ for(; file && *file;){
if (strlen(file) >= BUFSIZ) {
fprintf(stderr,_("namei: buf overflow\n"));
@@ -198,6 +205,20 @@
for(i = 0; i < lev; i++)
(void)printf(" ");
+
+ /*
+ * Previous element in the path wasn't directory, it means
+ * we cannot walk on *path* and check the actual element by lstat(), because
+ * there could be a component with same name. Try:
+ *
+ * $ touch a b
+ * $ namei a/b <-- "a" is not directory so namei shouldn't check for "b"
+ */
+ if (*lastmode && S_ISDIR(*lastmode)==0 && S_ISLNK(*lastmode)==0){
+ (void)printf(" ? %s - %s (%d)\n", buf, strerror(ENOENT), ENOENT);
+ return;
+ }
+
/*
* See what type of critter this file is
*/
@@ -207,6 +228,8 @@
return;
}
+ *lastmode = stb.st_mode;
+
switch(stb.st_mode & S_IFMT){
case S_IFDIR:
@@ -241,7 +264,6 @@
* Sigh, another symlink. Read its contents and
* call namei()
*/
-
bzero(sym, BUFSIZ);
if(readlink(buf, sym, BUFSIZ) == -1){
(void)printf(_(" ? problems reading symlink %s - %s (%d)\n"), buf, ERR);
@@ -255,11 +277,12 @@
if(symcount > 0 && symcount++ > MAXSYMLINKS){
(void)printf(_(" *** EXCEEDED UNIX LIMIT OF SYMLINKS ***\n"));
- symcount = -1;
} else {
(void)printf("\n");
- namei(sym, lev + 1);
+ namei(sym, lev + 1, lastmode);
}
+ if (symcount > MAXSYMLINKS)
+ return;
break;
case S_IFCHR:

View File

@ -9,7 +9,7 @@
Summary: A collection of basic system utilities. Summary: A collection of basic system utilities.
Name: util-linux Name: util-linux
Version: 2.13 Version: 2.13
Release: 0.46%{?dist} Release: 0.47%{?dist}
License: distributable License: distributable
Group: System Environment/Base Group: System Environment/Base
@ -237,6 +237,9 @@ Patch258: util-linux-2.13-mkdir_p.patch
Patch259: util-linux-2.13-fdisk-b-4096.patch Patch259: util-linux-2.13-fdisk-b-4096.patch
# leaking file descriptor # leaking file descriptor
Patch260: util-linux-2.13-more-CLOEXEC.patch Patch260: util-linux-2.13-more-CLOEXEC.patch
# 217240 - namei ignores non-directory components instead of saying "Not a directory"
# 217241 - namei enforces symlink limits inconsistently
Patch261: util-linux-2.13-namei-logic.patch
# When adding patches, please make sure that it is easy to find out what bug # the # When adding patches, please make sure that it is easy to find out what bug # the
# patch fixes. # patch fixes.
@ -336,6 +339,7 @@ cp %{SOURCE8} %{SOURCE9} .
%patch258 -p1 %patch258 -p1
%patch259 -p1 %patch259 -p1
%patch260 -p1 %patch260 -p1
%patch261 -p1
%build %build
unset LINGUAS || : unset LINGUAS || :
@ -746,6 +750,10 @@ exit 0
/sbin/losetup /sbin/losetup
%changelog %changelog
* Fri Dec 15 2006 Karel Zak <kzak@redhat.com> 2.13-0.47
- fix #217240 - namei ignores non-directory components instead of saying "Not a directory"
- fix #217241 - namei enforces symlink limits inconsistently
* Wed Dec 14 2006 Karel Zak <kzak@redhat.com> 2.13-0.46 * Wed Dec 14 2006 Karel Zak <kzak@redhat.com> 2.13-0.46
- fix leaking file descriptor in the more command (patch by Steve Grubb) - fix leaking file descriptor in the more command (patch by Steve Grubb)