Discussion:
[ast-developers] cd -@ doesn't work for '/' ...
Roland Mainz
2013-11-08 10:53:17 UTC
Permalink
Hi!

----

$ cd -@ / # doesn't work in ast-ksh.2013-10-10 on Solaris
11/B145/AMD64/64bit build:
-- snip --
$ ./arch/sol11.i386-64/bin/ksh -c 'cd -@ / ; echo $?'
./arch/sol11.i386-64/bin/ksh: cd: /dev/file/xattr@///@//: [No such
file or directory]
1
-- snip --
... the issue here is that the path mangeling removes all slashes
('/') until there is no slash left to represent the root directory...
;-(

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Roland Mainz
2013-11-10 02:24:23 UTC
Permalink
Post by Roland Mainz
-- snip --
file or directory]
1
-- snip --
... the issue here is that the path mangeling removes all slashes
('/') until there is no slash left to represent the root directory...
;-(
More data:
The issue seems to be an "off by one" issue. If $ cd -@ / # is called
then variables |t| and |r| in src/lib/libast/path/pathcanon.c line 523
are one byte from each other and both point to a byte with the value
'/':
-- snip --
519 char buf[2*PATH_MAX];
520
521 t = r - 2;
522 r = x;
523 if (t == r)
524 {
525 buf[0] = *path
== '/' ? '/' : '.';
526 buf[1] = 0;
527 }
528 else
529 {
530 memcpy(buf, r, t - r);
531 for (r = buf +
(t - r); r > buf && *(r - 1) == '/'; r--);
532 *r = 0;
533 }
-- snip --

Uhm... there are several ways to fix this (e.g. remove the |if (t ==
r)| branch and instead check for an empty buffer after the |*r = 0|)
... but what would be the preferred one ?

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Loading...