Mail Archives: djgpp-workers/1999/08/22/13:18:20
Hello,
when writing my new symlink code, I noticed following bug -
check if source and destination files are in the same
directory, is incorrect. You have:
if (strnicmp (src_abs, dest_abs, src_base - src_abs))
This test fails if e.g. source is "c:\command.com"
and destination is "c:\dir\command.com", because
src_base - src_abs gives 3, so only "c:\" from both
strings are compared, which gives incorrect result.
The patch follows -
Laurynas Biveinis
----------
--- symlink.c.old2 Tue Oct 28 20:22:54 1997
+++ symlink.c Sun Aug 22 17:34:36 1999
@@ -65,6 +65,7 @@
char dest_abs[FILENAME_MAX+5];
char *np, ropt[FILENAME_MAX+15]; /* some extra for ``runfile='' */
const char *src_base, *dest_base;
+ unsigned src_dir_len, dest_dir_len; /* For 'the same directory' check */
int v2_prog = 0;
@@ -74,7 +75,10 @@
dest_base = tail (dest_abs);
/* DJGPP symlinks must be in the same directory. */
- if (strnicmp (src_abs, dest_abs, src_base - src_abs))
+ src_dir_len = src_base - src_abs;
+ dest_dir_len = dest_base - dest_abs;
+ if (strnicmp (src_abs, dest_abs, (src_dir_len > dest_dir_len) ?
+ src_dir_len : dest_dir_len))
{
errno = EXDEV;
return -1;
- Raw text -