delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/08/22/13:18:20

Message-ID: <37C01A4C.AC7346AF@softhome.net>
Date: Sun, 22 Aug 1999 17:42:04 +0200
From: Laurynas Biveinis <lauras AT softhome DOT net>
X-Mailer: Mozilla 4.61 [en] (Win98; I)
X-Accept-Language: lt,en
MIME-Version: 1.0
To: DJGPP Workers <djgpp-workers AT delorie DOT com>
Subject: symlink() bug & fix
Reply-To: djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019